diff --git a/Bitrise.xcodeproj/project.pbxproj b/Bitrise.xcodeproj/project.pbxproj index ff2652ea..6964bbd4 100644 --- a/Bitrise.xcodeproj/project.pbxproj +++ b/Bitrise.xcodeproj/project.pbxproj @@ -130,6 +130,7 @@ D97355442402F980003FCE9B /* JetBrainsMono-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D973553C2402F980003FCE9B /* JetBrainsMono-Regular.ttf */; }; D97355452402F980003FCE9B /* JetBrainsMono-ExtraBold-Italic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D973553D2402F980003FCE9B /* JetBrainsMono-ExtraBold-Italic.ttf */; }; D9B2E7F123F94F5600C211F5 /* AMR_ANSIEscapeHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = D9B2E7F023F94F5600C211F5 /* AMR_ANSIEscapeHelper.m */; }; + D9E44BA2240C2CCB00DE96A6 /* BRLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = D9E44BA1240C2CCB00DE96A6 /* BRLogger.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -333,6 +334,8 @@ D973553D2402F980003FCE9B /* JetBrainsMono-ExtraBold-Italic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "JetBrainsMono-ExtraBold-Italic.ttf"; sourceTree = ""; }; D9B2E7EF23F94F5600C211F5 /* AMR_ANSIEscapeHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AMR_ANSIEscapeHelper.h; sourceTree = ""; }; D9B2E7F023F94F5600C211F5 /* AMR_ANSIEscapeHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMR_ANSIEscapeHelper.m; sourceTree = ""; }; + D9E44BA0240C2CCA00DE96A6 /* BRLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BRLogger.h; sourceTree = ""; }; + D9E44BA1240C2CCB00DE96A6 /* BRLogger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BRLogger.m; sourceTree = ""; }; EB550FAE0B12AA5E5BBED2E8 /* libPods-Bitrise.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Bitrise.a"; sourceTree = BUILT_PRODUCTS_DIR; }; EDCC38F36C8ABB179E968B54 /* libPods-BitriseTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-BitriseTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -643,6 +646,8 @@ isa = PBXGroup; children = ( 0E9F413720FEFA6A0083D646 /* BRMacro.h */, + D9E44BA0240C2CCA00DE96A6 /* BRLogger.h */, + D9E44BA1240C2CCB00DE96A6 /* BRLogger.m */, 0EDC5DDE21BBBB0A00AD41FE /* Queue */, 0EE1B85121B4363D005D5140 /* Collection Extensions */, ); @@ -1032,6 +1037,7 @@ 0E02C9AE22103ED100FCFE17 /* BRLogsDataSource.m in Sources */, 0EFB325C22020B5E0045C376 /* BRLogObserver.m in Sources */, 0E4AD0892205F9D200257E8E /* BRLogsRequest.m in Sources */, + D9E44BA2240C2CCB00DE96A6 /* BRLogger.m in Sources */, 0EBA9D6C2217F9EF007234EB /* BRLogInfo.m in Sources */, 0E52AB802242A4A60020A943 /* BRLogStorage.m in Sources */, 0EE1B85E21B4363D005D5140 /* NSSet+FRP.m in Sources */, diff --git a/Bitrise/AppDelegate.m b/Bitrise/AppDelegate.m index 1509cfb6..f03b9b5a 100644 --- a/Bitrise/AppDelegate.m +++ b/Bitrise/AppDelegate.m @@ -8,6 +8,7 @@ #import "AppDelegate.h" +#import "BRLogger.h" #import "BRAnalytics.h" #import "BRSyncCommand.h" #import "BRMainController.h" @@ -33,6 +34,7 @@ - (instancetype)init { if (self = [super init]) { #if DEBUG + [[BRLogger defaultLogger] setCurrentLogLevel:LL_VERBOSE]; [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints"]; #endif diff --git a/Bitrise/Container/BRContainerBuilder.m b/Bitrise/Container/BRContainerBuilder.m index b544bc06..1c5303f7 100644 --- a/Bitrise/Container/BRContainerBuilder.m +++ b/Bitrise/Container/BRContainerBuilder.m @@ -8,6 +8,8 @@ #import "BRContainerBuilder.h" +#import "BRLogger.h" + @implementation BRContainerBuilder - (NSPersistentContainer *)buildContainer { @@ -25,7 +27,7 @@ - (NSPersistentContainer *)buildContainerOfType:(NSString *)type { NSError *error; BOOL result = [[NSFileManager defaultManager] createDirectoryAtPath:appDirectoryURL.path withIntermediateDirectories:NO attributes:nil error:&error]; if (!result) { - NSLog(@"Failed to create app directory: %@", error); + BRLog(LL_WARN, LL_STORAGE, @"Failed to create app directory: %@", error); return nil; } } @@ -37,7 +39,7 @@ - (NSPersistentContainer *)buildContainerOfType:(NSString *)type { container.persistentStoreDescriptions = @[storeDescription]; [container loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) { if (!storeDescription) { - NSLog(@"Failed to load store: %@", error); + BRLog(LL_WARN, LL_STORAGE, @"Failed to load store: %@", error); } }]; diff --git a/Bitrise/Controller/Logs/BRLogsViewController.m b/Bitrise/Controller/Logs/BRLogsViewController.m index 50cbeff6..5c9735df 100644 --- a/Bitrise/Controller/Logs/BRLogsViewController.m +++ b/Bitrise/Controller/Logs/BRLogsViewController.m @@ -35,8 +35,6 @@ - (void)setBuildSlug:(NSString *)buildSlug { [self.logDataSource bindTextView:self.logTextView]; [self.logDataSource fetch:self.buildSlug]; - - NSLog(@"Controller: %@, observer: %@", self, self.logObserver); } @end diff --git a/Bitrise/Info.plist b/Bitrise/Info.plist index c4e7a19d..1b269d98 100644 --- a/Bitrise/Info.plist +++ b/Bitrise/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString $(MARKETING_VERSION) CFBundleVersion - 1134 + 1148 LSApplicationCategoryType public.app-category.developer-tools LSMinimumSystemVersion diff --git a/Bitrise/Networking/Commands/BRSyncCommand.m b/Bitrise/Networking/Commands/BRSyncCommand.m index 3e45db43..bf100921 100644 --- a/Bitrise/Networking/Commands/BRSyncCommand.m +++ b/Bitrise/Networking/Commands/BRSyncCommand.m @@ -15,8 +15,6 @@ @interface BRSyncCommand () @property (strong, nonatomic, readonly) BRSyncEngine *syncEngine; -@property (strong, nonatomic, readonly) BRLogObserver *logObserver; -@property (strong, nonatomic, readonly) BREnvironment *environment; @end @@ -27,14 +25,13 @@ - (instancetype)initSyncEngine:(BRSyncEngine *)engine environment:(BREnvironment *)environment { if (self = [super init]) { _syncEngine = engine; - _logObserver = logObserver; - _environment = environment; - __weak BRSyncCommand *weakSelf = self; _syncEngine.syncCallback = ^(BRSyncResult *result) { // Notifications NSArray *builds = [result.diff.started arrayByAddingObjectsFromArray:result.diff.finished]; - [weakSelf.environment postNotifications:builds forApp:result.app]; + if (builds.count > 0) { + [environment postNotifications:builds forApp:result.app]; + } #if FEATURE_LIVE_LOG // Logs observing @@ -44,7 +41,7 @@ - (instancetype)initSyncEngine:(BRSyncEngine *)engine }]]; [runningBuildsSlugs enumerateObjectsUsingBlock:^(NSString *buildSlug, BOOL *stop) { - [weakSelf.logObserver startObservingBuild:buildSlug]; + [logObserver startObservingBuild:buildSlug]; }]; #endif diff --git a/Bitrise/Networking/LogObserver/ASLogLoadingOperation.m b/Bitrise/Networking/LogObserver/ASLogLoadingOperation.m index 5b01b560..3b8b545c 100644 --- a/Bitrise/Networking/LogObserver/ASLogLoadingOperation.m +++ b/Bitrise/Networking/LogObserver/ASLogLoadingOperation.m @@ -8,6 +8,8 @@ #import "ASLogLoadingOperation.h" +#import "BRLogger.h" + #import "BRMacro.h" #import "ASLogObservingOperation.h" #import "BRBuildInfo.h" @@ -52,7 +54,7 @@ - (void)start { NSError *fetchError; BRBuild *build = [self.storage buildWithSlug:self.buildSlug error:&fetchError]; if (!build) { - NSLog(@"ASLogLoadingOperation: failed to get build: %@", fetchError); + BRLog(LL_WARN, LL_STORAGE, @"ASLogLoadingOperation: failed to get build: %@", fetchError); [self finish]; return; } @@ -83,7 +85,7 @@ - (void)finish { } - (void)loadLogs:(BRBuild *)build { - NSLog(@"ASLogLoadingOperation: fetching log: %@", self.buildSlug); + BRLog(LL_DEBUG, LL_STORAGE, @"ASLogLoadingOperation: fetching log: %@", self.buildSlug); BRLogsRequest *request = [[BRLogsRequest alloc] initWithToken:build.app.account.token appSlug:build.app.slug buildSlug:build.slug since:[build.log.timestamp timeIntervalSince1970]]; @@ -111,7 +113,7 @@ - (void)loadLogs:(BRBuild *)build { // Clean pervious logs if (![self.storage cleanLogs:build error:&cleanError]) { - NSLog(@"Failed to clean build logs: %@", cleanError); + BRLog(LL_WARN, LL_STORAGE, @"Failed to clean build logs: %@", cleanError); [self finish]; return; } @@ -123,9 +125,9 @@ - (void)loadLogs:(BRBuild *)build { BOOL logMarked = [self.storage markBuildLog:build.log loaded:YES error:&markError]; if (metadataSaved && logSaved && logMarked) { - NSLog(@"ASLogLoadingOperation: %@ - log saved", self.buildSlug); + BRLog(LL_DEBUG, LL_STORAGE, @"ASLogLoadingOperation: %@ - log saved", self.buildSlug); } else { - NSLog(@"ASLogLoadingOperation: Read log : %@\nSave log : %@\nMark loaded: %@", readingError, saveError, markError); + BRLog(LL_DEBUG, LL_STORAGE, @"ASLogLoadingOperation: Read log : %@\nSave log : %@\nMark loaded: %@", readingError, saveError, markError); } [self finish]; @@ -144,7 +146,7 @@ - (NSURL *)moveLogFile:(NSURL *)tmpURL { targetURL = [targetURL URLByAppendingPathComponent:tmpURL.lastPathComponent]; BOOL moveResult = [[NSFileManager defaultManager] moveItemAtURL:tmpURL toURL:targetURL error:&moveError]; if (!moveResult) { - NSLog(@"Failed to move log file: %@", moveError); + BRLog(LL_WARN, LL_STORAGE, @"Failed to move log file: %@", moveError); [super finish]; return nil; } diff --git a/Bitrise/Networking/LogObserver/ASLogObservingOperation.m b/Bitrise/Networking/LogObserver/ASLogObservingOperation.m index 51cacfff..7538e7c6 100644 --- a/Bitrise/Networking/LogObserver/ASLogObservingOperation.m +++ b/Bitrise/Networking/LogObserver/ASLogObservingOperation.m @@ -8,6 +8,8 @@ #import "ASLogObservingOperation.h" +#import "BRLogger.h" + #import "BRBuild+CoreDataClass.h" #import "BRBuildLog+CoreDataClass.h" #import "BRLogsRequest.h" @@ -71,7 +73,7 @@ - (void)fetchLogs { NSError *fetchError; BRBuild *build = [self.storage buildWithSlug:self.buildSlug error:&fetchError]; if (!build) { - NSLog(@"ASLogObservingOperation: failed to get build: %@", fetchError); + BRLog(LL_DEBUG, LL_LOGSYNC, @"ASLogObservingOperation: failed to get build: %@", fetchError); [self finish]; return; } @@ -80,7 +82,7 @@ - (void)fetchLogs { BRLogsRequest *request = [[BRLogsRequest alloc] initWithToken:build.app.account.token appSlug:build.app.slug buildSlug:build.slug since:fetchTime]; - NSLog(@"ASLogObservingOperation: %@, request timestamp: %f", self, fetchTime); + BRLog(LL_DEBUG, LL_LOGSYNC, @"ASLogObservingOperation: %@, request timestamp: %f", self, fetchTime); [self.api loadLogs:request completion:^(BRLogInfo *logInfo, NSError *error) { if (logInfo.rawLog) { NSError *saveError; @@ -93,17 +95,17 @@ - (void)fetchLogs { [self.receivedChunks addIndexes:[logInfo chunkPositions]]; - NSLog(@"ASLogObservingOperation: got chunks: %lu, filtered: %lu", [logInfo.rawLog[@"log_chunks"] count], chunks.count); - NSLog(@"ASLogObservingOperation: got timestamp: %@", logInfo.rawLog[@"timestamp"]); + BRLog(LL_DEBUG, LL_LOGSYNC, @"ASLogObservingOperation: got chunks: %lu, filtered: %lu", [logInfo.rawLog[@"log_chunks"] count], chunks.count); + BRLog(LL_DEBUG, LL_LOGSYNC, @"ASLogObservingOperation: got timestamp: %@", logInfo.rawLog[@"timestamp"]); } if (build.log.archived) { - NSLog(@"ASLogObservingOperation: build log archived, build finished, stopping observing..."); + BRLog(LL_DEBUG, LL_LOGSYNC, @"ASLogObservingOperation: build log archived, build finished, stopping observing..."); [self finish]; } NSTimeInterval endTime = [[NSDate date] timeIntervalSince1970]; - NSLog(@"ASLogObservingOperation: fetch time: %f sec.", endTime - startTime); + BRLog(LL_DEBUG, LL_LOGSYNC, @"ASLogObservingOperation: fetch time: %f sec.", endTime - startTime); }]; }]; } diff --git a/Bitrise/Networking/LogObserver/BRLogObserver.m b/Bitrise/Networking/LogObserver/BRLogObserver.m index cf3087ba..46959441 100644 --- a/Bitrise/Networking/LogObserver/BRLogObserver.m +++ b/Bitrise/Networking/LogObserver/BRLogObserver.m @@ -8,6 +8,7 @@ #import "BRLogObserver.h" +#import "BRLogger.h" #import "NSArray+FRP.h" #import "ASQueue.h" @@ -37,23 +38,23 @@ - (instancetype)initWithAPI:(BRBitriseAPI *)api storage:(BRStorage *)storage { - (void)startObservingBuild:(NSString *)buildSlug { @synchronized (self) { - NSLog(@"Observer: %@, build %@, started...", self, buildSlug); + BRLog(LL_DEBUG, LL_LOGSYNC, @"Observer: %@, build %@, started...", self, buildSlug); if ([[self operationsForBuild:buildSlug] count] > 0) { - NSLog(@"BRLogObserver: has observing operation: %@, skipping...", buildSlug); + BRLog(LL_DEBUG, LL_LOGSYNC, @"BRLogObserver: has observing operation: %@, skipping...", buildSlug); return; } ASLogObservingOperation *operation = [[ASLogObservingOperation alloc] initWithStorage:self.storage api:self.API buildSlug:buildSlug]; [self.queue addOperation:operation]; - NSLog(@"BRLogObserver: added observing operation: %@", buildSlug); + BRLog(LL_DEBUG, LL_LOGSYNC, @"BRLogObserver: added observing operation: %@", buildSlug); } } - (void)stopObservingBuild:(NSString *)buildSlug { @synchronized (self) { [[self operationsForBuild:buildSlug] enumerateObjectsUsingBlock:^(ASOperation *operation, NSUInteger idx, BOOL *stop) { - NSLog(@"BRLogObserver: cancelling observing operation: %@", buildSlug); + BRLog(LL_DEBUG, LL_LOGSYNC, @"BRLogObserver: cancelling observing operation: %@", buildSlug); [operation cancel]; }]; } @@ -64,7 +65,7 @@ - (void)loadLogsForBuild:(NSString *)buildSlug callback:(BRLogLoadingCallback)ca ASLogLoadingOperation *operation = [[ASLogLoadingOperation alloc] initWithStorage:self.storage api:self.API buildSlug:buildSlug]; [operation setLoadingCallback:callback]; [self.queue addOperation:operation]; - NSLog(@"BRLogObserver: added load operation: %@", buildSlug); + BRLog(LL_DEBUG, LL_LOGSYNC, @"BRLogObserver: added load operation: %@", buildSlug); } } diff --git a/Bitrise/Storage/BRStorage.m b/Bitrise/Storage/BRStorage.m index 6d2a9901..6c4f99b8 100644 --- a/Bitrise/Storage/BRStorage.m +++ b/Bitrise/Storage/BRStorage.m @@ -10,6 +10,7 @@ #import +#import "BRLogger.h" #import "NSArray+FRP.h" #import "BRMacro.h" @@ -197,7 +198,7 @@ - (BOOL)saveBuilds:(NSArray *)buildsInfo forApp:(NSString *)appS }]; result = [self saveContext:self.context error:error]; } else { - NSLog(@"Failed to save builds: %@", *error); + BRLog(LL_WARN, LL_STORAGE, @"Failed to save builds: %@", *error); result = NO; } diff --git a/Bitrise/Storage/Data Sources/BRAccountsDataSource.m b/Bitrise/Storage/Data Sources/BRAccountsDataSource.m index c28f8b25..ffe2701e 100644 --- a/Bitrise/Storage/Data Sources/BRAccountsDataSource.m +++ b/Bitrise/Storage/Data Sources/BRAccountsDataSource.m @@ -8,6 +8,8 @@ #import "BRAccountsDataSource.h" +#import "BRLogger.h" + #import #import #import "BTRAccount+CoreDataClass.h" @@ -48,7 +50,7 @@ - (void)bind:(NSOutlineView *)outlineView { - (void)fetch { NSError *fetchError = nil; if (![self.accountsFRC performFetch:&fetchError]) { - NSLog(@"Failed to fetch apps: %@", fetchError); + BRLog(LL_WARN, LL_STORAGE, @"Failed to fetch apps: %@", fetchError); } [self.outlineView reloadData]; } diff --git a/Bitrise/Storage/Data Sources/BRAppsDataSource.m b/Bitrise/Storage/Data Sources/BRAppsDataSource.m index 42e0b967..d3c8264a 100644 --- a/Bitrise/Storage/Data Sources/BRAppsDataSource.m +++ b/Bitrise/Storage/Data Sources/BRAppsDataSource.m @@ -10,6 +10,8 @@ #import +#import "BRLogger.h" + #import "BRAppCellView.h" #import "BRBuildCellView.h" @@ -63,7 +65,7 @@ - (NSFetchedResultsController *)buildBuildsFRC:(NSManagedObjectContext *)context - (void)fetch { NSError *fetchError = nil; if (![self.buildsFRC performFetch:&fetchError]) { - NSLog(@"Failed to fetch builds: %@", fetchError); + BRLog(LL_WARN, LL_STORAGE, @"Failed to fetch builds: %@", fetchError); } [self.outlineView reloadData]; } diff --git a/Bitrise/Storage/Data Sources/BRLogsDataSource.m b/Bitrise/Storage/Data Sources/BRLogsDataSource.m index d4f7cb4a..2aede5cc 100644 --- a/Bitrise/Storage/Data Sources/BRLogsDataSource.m +++ b/Bitrise/Storage/Data Sources/BRLogsDataSource.m @@ -10,6 +10,7 @@ #import "BRLogsDataSource.h" +#import "BRLogger.h" #import "BRMacro.h" #import "BRLogLine+CoreDataClass.h" #import "BRLogStep+CoreDataClass.h" @@ -60,7 +61,7 @@ - (void)fetch:(NSString *)buildSlug { NSError *fetchError = nil; if (![self.logFRC performFetch:&fetchError]) { - NSLog(@"Failed to fetch logs: %@ - %@", buildSlug, fetchError); + BRLog(LL_WARN, LL_STORAGE, @"Failed to fetch logs: %@ - %@", buildSlug, fetchError); } [self updateContent]; diff --git a/Bitrise/Sync/BRSyncOperation.m b/Bitrise/Sync/BRSyncOperation.m index 46eb13f1..3462ffa9 100644 --- a/Bitrise/Sync/BRSyncOperation.m +++ b/Bitrise/Sync/BRSyncOperation.m @@ -8,7 +8,8 @@ #import "BRSyncOperation.h" -//#import "ASTracer.h" +#import "BRLogger.h" + #import "BRBuildStateInfo.h" #import "NSArray+FRP.h" #import "BRBuild+CoreDataClass.h" @@ -43,51 +44,33 @@ - (void)start { self.group = dispatch_group_create(); [self.storage perform:^{ - - //NSString *scopeName = [NSString stringWithFormat:@"%@", self.queue]; - //[[ASTracer tracer] startSpan:@"Accounts fetch" inScope:scopeName]; - NSError *accFetchError; NSArray *accounts = [self.storage accounts:&accFetchError]; if (!accounts) { - NSLog(@"Failed to get accounts: %@", accFetchError); + BRLog(LL_DEBUG, LL_STORAGE, @"Failed to get accounts: %@", accFetchError); [super finish]; return; } if (accounts.count == 0) { - NSLog(@"No accounts, nothing to do..."); + BRLog(LL_DEBUG, LL_STORAGE, @"No accounts, nothing to do..."); [super finish]; return; } - //[[ASTracer tracer] stopSpan:@"Accounts fetch" inScope:scopeName sucess:YES]; - [accounts enumerateObjectsUsingBlock:^(BTRAccount *account, NSUInteger idx, BOOL *stop) { - dispatch_group_enter(self.group); - - //[[ASTracer tracer] startSpan:[NSString stringWithFormat:@"acc fetch: %@", account.slug] inScope:scopeName]; - BRAppsRequest *appsRequest = [[BRAppsRequest alloc] initWithToken:account.token]; [self.api getApps:appsRequest completion:^(NSArray *appsInfo, NSError *error) { - - //[[ASTracer tracer] stopSpan:[NSString stringWithFormat:@"acc fetch: %@", account.slug] inScope:scopeName sucess:YES]; - - //NSString *spanName = [NSString stringWithFormat:@"acc update: %@", account.slug]; - //[[ASTracer tracer] startSpan:spanName inScope:scopeName]; - if (!appsInfo) { - NSLog(@"Failed to get apps from API: %@", error); - //[[ASTracer tracer] stopSpan:spanName inScope:scopeName sucess:NO]; + BRLog(LL_WARN, LL_STORAGE, @"Failed to get apps from API: %@", error); [super finish]; return; } NSError *updateAppsError; if (![self.storage updateApps:appsInfo forAccount:account error:&updateAppsError]) { - NSLog(@"Failed to update apps: %@", updateAppsError); - //[[ASTracer tracer] stopSpan:spanName inScope:scopeName sucess:NO]; + BRLog(LL_WARN, LL_STORAGE, @"Failed to update apps: %@", updateAppsError); [super finish]; return; } @@ -95,8 +78,7 @@ - (void)start { NSError *appsFetchError; NSArray *apps = [self.storage appsForAccount:account error:&appsFetchError]; if (!apps) { - NSLog(@"Failed to fetch updated apps: %@", appsFetchError); - //[[ASTracer tracer] stopSpan:spanName inScope:scopeName sucess:NO]; + BRLog(LL_WARN, LL_STORAGE, @"Failed to fetch updated apps: %@", appsFetchError); [super finish]; return; } @@ -109,8 +91,6 @@ - (void)start { [self updateBuilds:app token:account.token runningBuilds:runningBuildSlugs]; }]; - //[[ASTracer tracer] stopSpan:spanName inScope:scopeName sucess:YES]; - dispatch_group_leave(self.group); }]; }]; @@ -143,10 +123,10 @@ - (void)updateBuilds:(BRApp *)app token:(NSString *)token runningBuilds:(NSArray self.syncCallback(result); } if (![self.storage saveBuilds:builds forApp:app.slug error:&error]) { - NSLog(@"Failed to save builds: %@", error); + BRLog(LL_WARN, LL_STORAGE, @"Failed to save builds: %@", error); } } else { - NSLog(@"Failed to get builds from API: %@", error); + BRLog(LL_WARN, LL_STORAGE, @"Failed to get builds from API: %@", error); } dispatch_group_leave(self.group); @@ -160,16 +140,16 @@ - (BRSyncDiff *)diffForBuilds:(NSArray *)remoteBuilds runningBui [remoteBuilds enumerateObjectsUsingBlock:^(BRBuildInfo *remoteBuild, NSUInteger idx, BOOL *stop) { if ([runningBuilds containsObject:remoteBuild.slug]) { if (remoteBuild.stateInfo.state != BRBuildStateHold && remoteBuild.stateInfo.state != BRBuildStateInProgress) { - NSLog(@"Finished build: %@", remoteBuild.slug); + BRLog(LL_DEBUG, LL_CORE, @"Finished build: %@", remoteBuild.slug); [finished addObject:remoteBuild]; } if (remoteBuild.stateInfo.state == BRBuildStateInProgress) { - NSLog(@"Running build: %@", remoteBuild.slug); + BRLog(LL_DEBUG, LL_CORE, @"Running build: %@", remoteBuild.slug); [running addObject:remoteBuild]; } } else { if (remoteBuild.stateInfo.state == BRBuildStateHold || remoteBuild.stateInfo.state == BRBuildStateInProgress) { - NSLog(@"Started build: %@", remoteBuild.slug); + BRLog(LL_DEBUG, LL_CORE, @"Started build: %@", remoteBuild.slug); [started addObject:remoteBuild]; } } diff --git a/Bitrise/Tools/BRLogger.h b/Bitrise/Tools/BRLogger.h new file mode 100644 index 00000000..e673b5ef --- /dev/null +++ b/Bitrise/Tools/BRLogger.h @@ -0,0 +1,42 @@ +// +// BRLogger.h +// BitBot +// +// Created by Zardoz on 30.04.12. +// Copyright (c) 2012 BitBot. All rights reserved. +// + +#import + +#define BRLog(level,tag_value,message,...) [[BRLogger defaultLogger] logLevel:level tag:tag_value file:__FILE__ lineNumber:__LINE__ format:(message),##__VA_ARGS__] + +@class BRLogEntry; + +// Log tags +static NSString * const LL_WEBSOCKET = @"UI"; +static NSString * const LL_REQUESTFLOW = @"SYNC"; +static NSString * const LL_STORAGE = @"STORAGE"; +static NSString * const LL_CORE = @"CORE"; +static NSString * const LL_LOGSYNC = @"LOGSYNC"; + + +typedef NS_ENUM(NSUInteger, BRLogLevel) { + LL_VERBOSE = 1 << 0, + LL_DEBUG = 1 << 1, + LL_INFO = 1 << 2, + LL_WARN = 1 << 3, + LL_ERROR = 1 << 4, + LL_ASSERT = 1 << 5, + + LL_NONE = NSUIntegerMax +}; + +@interface BRLogger : NSObject + +@property (nonatomic, assign) BRLogLevel currentLogLevel; + ++ (id)defaultLogger; + +- (void)logLevel:(BRLogLevel)level tag:(NSString *)tag file:(char const *)sourceFile lineNumber:(int)lineNumber format:(NSString *)format, ...; + +@end diff --git a/Bitrise/Tools/BRLogger.m b/Bitrise/Tools/BRLogger.m new file mode 100644 index 00000000..3e2d38af --- /dev/null +++ b/Bitrise/Tools/BRLogger.m @@ -0,0 +1,45 @@ +// +// BRLogger.m +// BitBot +// +// Created by Zardoz on 30.04.12. +// Copyright (c) 2012 BitBot. All rights reserved. +// + +#import "BRLogger.h" + +void BR_Raw_NSLog(NSString *format, ...) { + va_list ap; + va_start(ap, format); + NSLogv(format, ap); + va_end(ap); +} + +@implementation BRLogger + ++ (id)defaultLogger { + static BRLogger *defaultLogger = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + defaultLogger = [BRLogger new]; + [defaultLogger setCurrentLogLevel:LL_NONE]; + }); + + return defaultLogger; +} + +- (void)logLevel:(BRLogLevel)level tag:(NSString *)tag file:(const char *)sourceFile lineNumber:(int)lineNumber format:(NSString *)format, ... { + // Skip if log level is lower than current + if ([[BRLogger defaultLogger] currentLogLevel] > level) return; + + // Pass to system logging + va_list args; + va_start(args, format); + NSString *logMessage = [[NSString alloc] initWithFormat:format arguments:args]; + va_end(args); + + NSString *fileName = [[NSString alloc] initWithBytes:sourceFile length:strlen(sourceFile) encoding:NSUTF8StringEncoding]; + BR_Raw_NSLog(@"[%s:%d] %@ - %@", [[fileName lastPathComponent] UTF8String], lineNumber, tag, logMessage); +} + +@end diff --git a/Bitrise/Tools/Queue/ASOperation.m b/Bitrise/Tools/Queue/ASOperation.m index 29d01f83..1d533aae 100644 --- a/Bitrise/Tools/Queue/ASOperation.m +++ b/Bitrise/Tools/Queue/ASOperation.m @@ -8,6 +8,8 @@ #import "ASOperation.h" +#import "BRLogger.h" + @interface ASOperation () @property (assign, nonatomic) NSTimeInterval duration; @@ -57,7 +59,7 @@ - (void)trackDuration:(BOOL)processing { NSTimeInterval current = [[NSDate date] timeIntervalSince1970]; self.duration = processing ? current : current - self.duration; if (!processing) { - NSLog(@"%@: %f", NSStringFromClass([self class]), self.duration); + BRLog(LL_DEBUG, LL_CORE, @"%@: %f", NSStringFromClass([self class]), self.duration); } } diff --git a/Bitrise/View/BRProgressObserver.m b/Bitrise/View/BRProgressObserver.m index 6963bc8a..f2c05910 100644 --- a/Bitrise/View/BRProgressObserver.m +++ b/Bitrise/View/BRProgressObserver.m @@ -8,6 +8,8 @@ #import "BRProgressObserver.h" +#import "BRLogger.h" + static void *BRProgressObserverContext = &BRProgressObserverContext; static NSString * const kProgressFractionKey = @"fractionCompleted"; @@ -48,7 +50,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N dispatch_async(dispatch_get_main_queue(), ^{ if ([keyPath isEqualToString:kProgressFractionKey]) { self.indicator.doubleValue = [(NSProgress *)object fractionCompleted]; - NSLog(@"%f", self.indicator.doubleValue); + BRLog(LL_DEBUG, LL_STORAGE, @"%f", self.indicator.doubleValue); } }); } else { diff --git a/Bitrise/View/Base.lproj/Main.storyboard b/Bitrise/View/Base.lproj/Main.storyboard index 8d72509b..78846773 100644 --- a/Bitrise/View/Base.lproj/Main.storyboard +++ b/Bitrise/View/Base.lproj/Main.storyboard @@ -712,7 +712,7 @@ - +