Skip to content

Commit 3096daf

Browse files
committed
Added logger, fixed notification related memory issue
1 parent f257f48 commit 3096daf

19 files changed

Lines changed: 159 additions & 72 deletions

Bitrise.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
D97355442402F980003FCE9B /* JetBrainsMono-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D973553C2402F980003FCE9B /* JetBrainsMono-Regular.ttf */; };
131131
D97355452402F980003FCE9B /* JetBrainsMono-ExtraBold-Italic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D973553D2402F980003FCE9B /* JetBrainsMono-ExtraBold-Italic.ttf */; };
132132
D9B2E7F123F94F5600C211F5 /* AMR_ANSIEscapeHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = D9B2E7F023F94F5600C211F5 /* AMR_ANSIEscapeHelper.m */; };
133+
D9E44BA2240C2CCB00DE96A6 /* BRLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = D9E44BA1240C2CCB00DE96A6 /* BRLogger.m */; };
133134
/* End PBXBuildFile section */
134135

135136
/* Begin PBXContainerItemProxy section */
@@ -333,6 +334,8 @@
333334
D973553D2402F980003FCE9B /* JetBrainsMono-ExtraBold-Italic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "JetBrainsMono-ExtraBold-Italic.ttf"; sourceTree = "<group>"; };
334335
D9B2E7EF23F94F5600C211F5 /* AMR_ANSIEscapeHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AMR_ANSIEscapeHelper.h; sourceTree = "<group>"; };
335336
D9B2E7F023F94F5600C211F5 /* AMR_ANSIEscapeHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMR_ANSIEscapeHelper.m; sourceTree = "<group>"; };
337+
D9E44BA0240C2CCA00DE96A6 /* BRLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BRLogger.h; sourceTree = "<group>"; };
338+
D9E44BA1240C2CCB00DE96A6 /* BRLogger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BRLogger.m; sourceTree = "<group>"; };
336339
EB550FAE0B12AA5E5BBED2E8 /* libPods-Bitrise.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Bitrise.a"; sourceTree = BUILT_PRODUCTS_DIR; };
337340
EDCC38F36C8ABB179E968B54 /* libPods-BitriseTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-BitriseTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
338341
/* End PBXFileReference section */
@@ -643,6 +646,8 @@
643646
isa = PBXGroup;
644647
children = (
645648
0E9F413720FEFA6A0083D646 /* BRMacro.h */,
649+
D9E44BA0240C2CCA00DE96A6 /* BRLogger.h */,
650+
D9E44BA1240C2CCB00DE96A6 /* BRLogger.m */,
646651
0EDC5DDE21BBBB0A00AD41FE /* Queue */,
647652
0EE1B85121B4363D005D5140 /* Collection Extensions */,
648653
);
@@ -1032,6 +1037,7 @@
10321037
0E02C9AE22103ED100FCFE17 /* BRLogsDataSource.m in Sources */,
10331038
0EFB325C22020B5E0045C376 /* BRLogObserver.m in Sources */,
10341039
0E4AD0892205F9D200257E8E /* BRLogsRequest.m in Sources */,
1040+
D9E44BA2240C2CCB00DE96A6 /* BRLogger.m in Sources */,
10351041
0EBA9D6C2217F9EF007234EB /* BRLogInfo.m in Sources */,
10361042
0E52AB802242A4A60020A943 /* BRLogStorage.m in Sources */,
10371043
0EE1B85E21B4363D005D5140 /* NSSet+FRP.m in Sources */,

Bitrise/AppDelegate.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#import "AppDelegate.h"
1010

11+
#import "BRLogger.h"
1112
#import "BRAnalytics.h"
1213
#import "BRSyncCommand.h"
1314
#import "BRMainController.h"
@@ -33,6 +34,7 @@ - (instancetype)init {
3334
if (self = [super init]) {
3435

3536
#if DEBUG
37+
[[BRLogger defaultLogger] setCurrentLogLevel:LL_VERBOSE];
3638
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints"];
3739
#endif
3840

Bitrise/Container/BRContainerBuilder.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#import "BRContainerBuilder.h"
1010

11+
#import "BRLogger.h"
12+
1113
@implementation BRContainerBuilder
1214

1315
- (NSPersistentContainer *)buildContainer {
@@ -25,7 +27,7 @@ - (NSPersistentContainer *)buildContainerOfType:(NSString *)type {
2527
NSError *error;
2628
BOOL result = [[NSFileManager defaultManager] createDirectoryAtPath:appDirectoryURL.path withIntermediateDirectories:NO attributes:nil error:&error];
2729
if (!result) {
28-
NSLog(@"Failed to create app directory: %@", error);
30+
BRLog(LL_WARN, LL_STORAGE, @"Failed to create app directory: %@", error);
2931
return nil;
3032
}
3133
}
@@ -37,7 +39,7 @@ - (NSPersistentContainer *)buildContainerOfType:(NSString *)type {
3739
container.persistentStoreDescriptions = @[storeDescription];
3840
[container loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) {
3941
if (!storeDescription) {
40-
NSLog(@"Failed to load store: %@", error);
42+
BRLog(LL_WARN, LL_STORAGE, @"Failed to load store: %@", error);
4143
}
4244
}];
4345

Bitrise/Controller/Logs/BRLogsViewController.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ - (void)setBuildSlug:(NSString *)buildSlug {
3535

3636
[self.logDataSource bindTextView:self.logTextView];
3737
[self.logDataSource fetch:self.buildSlug];
38-
39-
NSLog(@"Controller: %@, observer: %@", self, self.logObserver);
4038
}
4139

4240
@end

Bitrise/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>$(MARKETING_VERSION)</string>
2121
<key>CFBundleVersion</key>
22-
<string>1134</string>
22+
<string>1148</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.developer-tools</string>
2525
<key>LSMinimumSystemVersion</key>

Bitrise/Networking/Commands/BRSyncCommand.m

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
@interface BRSyncCommand ()
1616

1717
@property (strong, nonatomic, readonly) BRSyncEngine *syncEngine;
18-
@property (strong, nonatomic, readonly) BRLogObserver *logObserver;
19-
@property (strong, nonatomic, readonly) BREnvironment *environment;
2018

2119
@end
2220

@@ -27,14 +25,13 @@ - (instancetype)initSyncEngine:(BRSyncEngine *)engine
2725
environment:(BREnvironment *)environment {
2826
if (self = [super init]) {
2927
_syncEngine = engine;
30-
_logObserver = logObserver;
31-
_environment = environment;
3228

33-
__weak BRSyncCommand *weakSelf = self;
3429
_syncEngine.syncCallback = ^(BRSyncResult *result) {
3530
// Notifications
3631
NSArray *builds = [result.diff.started arrayByAddingObjectsFromArray:result.diff.finished];
37-
[weakSelf.environment postNotifications:builds forApp:result.app];
32+
if (builds.count > 0) {
33+
[environment postNotifications:builds forApp:result.app];
34+
}
3835

3936
#if FEATURE_LIVE_LOG
4037
// Logs observing
@@ -44,7 +41,7 @@ - (instancetype)initSyncEngine:(BRSyncEngine *)engine
4441
}]];
4542

4643
[runningBuildsSlugs enumerateObjectsUsingBlock:^(NSString *buildSlug, BOOL *stop) {
47-
[weakSelf.logObserver startObservingBuild:buildSlug];
44+
[logObserver startObservingBuild:buildSlug];
4845
}];
4946
#endif
5047

Bitrise/Networking/LogObserver/ASLogLoadingOperation.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#import "ASLogLoadingOperation.h"
1010

11+
#import "BRLogger.h"
12+
1113
#import "BRMacro.h"
1214
#import "ASLogObservingOperation.h"
1315
#import "BRBuildInfo.h"
@@ -52,7 +54,7 @@ - (void)start {
5254
NSError *fetchError;
5355
BRBuild *build = [self.storage buildWithSlug:self.buildSlug error:&fetchError];
5456
if (!build) {
55-
NSLog(@"ASLogLoadingOperation: failed to get build: %@", fetchError);
57+
BRLog(LL_WARN, LL_STORAGE, @"ASLogLoadingOperation: failed to get build: %@", fetchError);
5658
[self finish];
5759
return;
5860
}
@@ -83,7 +85,7 @@ - (void)finish {
8385
}
8486

8587
- (void)loadLogs:(BRBuild *)build {
86-
NSLog(@"ASLogLoadingOperation: fetching log: %@", self.buildSlug);
88+
BRLog(LL_DEBUG, LL_STORAGE, @"ASLogLoadingOperation: fetching log: %@", self.buildSlug);
8789
BRLogsRequest *request = [[BRLogsRequest alloc] initWithToken:build.app.account.token
8890
appSlug:build.app.slug
8991
buildSlug:build.slug since:[build.log.timestamp timeIntervalSince1970]];
@@ -111,7 +113,7 @@ - (void)loadLogs:(BRBuild *)build {
111113

112114
// Clean pervious logs
113115
if (![self.storage cleanLogs:build error:&cleanError]) {
114-
NSLog(@"Failed to clean build logs: %@", cleanError);
116+
BRLog(LL_WARN, LL_STORAGE, @"Failed to clean build logs: %@", cleanError);
115117
[self finish];
116118
return;
117119
}
@@ -123,9 +125,9 @@ - (void)loadLogs:(BRBuild *)build {
123125
BOOL logMarked = [self.storage markBuildLog:build.log loaded:YES error:&markError];
124126

125127
if (metadataSaved && logSaved && logMarked) {
126-
NSLog(@"ASLogLoadingOperation: %@ - log saved", self.buildSlug);
128+
BRLog(LL_DEBUG, LL_STORAGE, @"ASLogLoadingOperation: %@ - log saved", self.buildSlug);
127129
} else {
128-
NSLog(@"ASLogLoadingOperation: Read log : %@\nSave log : %@\nMark loaded: %@", readingError, saveError, markError);
130+
BRLog(LL_DEBUG, LL_STORAGE, @"ASLogLoadingOperation: Read log : %@\nSave log : %@\nMark loaded: %@", readingError, saveError, markError);
129131
}
130132

131133
[self finish];
@@ -144,7 +146,7 @@ - (NSURL *)moveLogFile:(NSURL *)tmpURL {
144146
targetURL = [targetURL URLByAppendingPathComponent:tmpURL.lastPathComponent];
145147
BOOL moveResult = [[NSFileManager defaultManager] moveItemAtURL:tmpURL toURL:targetURL error:&moveError];
146148
if (!moveResult) {
147-
NSLog(@"Failed to move log file: %@", moveError);
149+
BRLog(LL_WARN, LL_STORAGE, @"Failed to move log file: %@", moveError);
148150
[super finish];
149151
return nil;
150152
}

Bitrise/Networking/LogObserver/ASLogObservingOperation.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#import "ASLogObservingOperation.h"
1010

11+
#import "BRLogger.h"
12+
1113
#import "BRBuild+CoreDataClass.h"
1214
#import "BRBuildLog+CoreDataClass.h"
1315
#import "BRLogsRequest.h"
@@ -71,7 +73,7 @@ - (void)fetchLogs {
7173
NSError *fetchError;
7274
BRBuild *build = [self.storage buildWithSlug:self.buildSlug error:&fetchError];
7375
if (!build) {
74-
NSLog(@"ASLogObservingOperation: failed to get build: %@", fetchError);
76+
BRLog(LL_DEBUG, LL_LOGSYNC, @"ASLogObservingOperation: failed to get build: %@", fetchError);
7577
[self finish];
7678
return;
7779
}
@@ -80,7 +82,7 @@ - (void)fetchLogs {
8082
BRLogsRequest *request = [[BRLogsRequest alloc] initWithToken:build.app.account.token
8183
appSlug:build.app.slug
8284
buildSlug:build.slug since:fetchTime];
83-
NSLog(@"ASLogObservingOperation: %@, request timestamp: %f", self, fetchTime);
85+
BRLog(LL_DEBUG, LL_LOGSYNC, @"ASLogObservingOperation: %@, request timestamp: %f", self, fetchTime);
8486
[self.api loadLogs:request completion:^(BRLogInfo *logInfo, NSError *error) {
8587
if (logInfo.rawLog) {
8688
NSError *saveError;
@@ -93,17 +95,17 @@ - (void)fetchLogs {
9395

9496
[self.receivedChunks addIndexes:[logInfo chunkPositions]];
9597

96-
NSLog(@"ASLogObservingOperation: got chunks: %lu, filtered: %lu", [logInfo.rawLog[@"log_chunks"] count], chunks.count);
97-
NSLog(@"ASLogObservingOperation: got timestamp: %@", logInfo.rawLog[@"timestamp"]);
98+
BRLog(LL_DEBUG, LL_LOGSYNC, @"ASLogObservingOperation: got chunks: %lu, filtered: %lu", [logInfo.rawLog[@"log_chunks"] count], chunks.count);
99+
BRLog(LL_DEBUG, LL_LOGSYNC, @"ASLogObservingOperation: got timestamp: %@", logInfo.rawLog[@"timestamp"]);
98100
}
99101

100102
if (build.log.archived) {
101-
NSLog(@"ASLogObservingOperation: build log archived, build finished, stopping observing...");
103+
BRLog(LL_DEBUG, LL_LOGSYNC, @"ASLogObservingOperation: build log archived, build finished, stopping observing...");
102104
[self finish];
103105
}
104106

105107
NSTimeInterval endTime = [[NSDate date] timeIntervalSince1970];
106-
NSLog(@"ASLogObservingOperation: fetch time: %f sec.", endTime - startTime);
108+
BRLog(LL_DEBUG, LL_LOGSYNC, @"ASLogObservingOperation: fetch time: %f sec.", endTime - startTime);
107109
}];
108110
}];
109111
}

Bitrise/Networking/LogObserver/BRLogObserver.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#import "BRLogObserver.h"
1010

11+
#import "BRLogger.h"
1112
#import "NSArray+FRP.h"
1213

1314
#import "ASQueue.h"
@@ -37,23 +38,23 @@ - (instancetype)initWithAPI:(BRBitriseAPI *)api storage:(BRStorage *)storage {
3738

3839
- (void)startObservingBuild:(NSString *)buildSlug {
3940
@synchronized (self) {
40-
NSLog(@"Observer: %@, build %@, started...", self, buildSlug);
41+
BRLog(LL_DEBUG, LL_LOGSYNC, @"Observer: %@, build %@, started...", self, buildSlug);
4142

4243
if ([[self operationsForBuild:buildSlug] count] > 0) {
43-
NSLog(@"BRLogObserver: has observing operation: %@, skipping...", buildSlug);
44+
BRLog(LL_DEBUG, LL_LOGSYNC, @"BRLogObserver: has observing operation: %@, skipping...", buildSlug);
4445
return;
4546
}
4647

4748
ASLogObservingOperation *operation = [[ASLogObservingOperation alloc] initWithStorage:self.storage api:self.API buildSlug:buildSlug];
4849
[self.queue addOperation:operation];
49-
NSLog(@"BRLogObserver: added observing operation: %@", buildSlug);
50+
BRLog(LL_DEBUG, LL_LOGSYNC, @"BRLogObserver: added observing operation: %@", buildSlug);
5051
}
5152
}
5253

5354
- (void)stopObservingBuild:(NSString *)buildSlug {
5455
@synchronized (self) {
5556
[[self operationsForBuild:buildSlug] enumerateObjectsUsingBlock:^(ASOperation <ASLogOperation> *operation, NSUInteger idx, BOOL *stop) {
56-
NSLog(@"BRLogObserver: cancelling observing operation: %@", buildSlug);
57+
BRLog(LL_DEBUG, LL_LOGSYNC, @"BRLogObserver: cancelling observing operation: %@", buildSlug);
5758
[operation cancel];
5859
}];
5960
}
@@ -64,7 +65,7 @@ - (void)loadLogsForBuild:(NSString *)buildSlug callback:(BRLogLoadingCallback)ca
6465
ASLogLoadingOperation *operation = [[ASLogLoadingOperation alloc] initWithStorage:self.storage api:self.API buildSlug:buildSlug];
6566
[operation setLoadingCallback:callback];
6667
[self.queue addOperation:operation];
67-
NSLog(@"BRLogObserver: added load operation: %@", buildSlug);
68+
BRLog(LL_DEBUG, LL_LOGSYNC, @"BRLogObserver: added load operation: %@", buildSlug);
6869
}
6970
}
7071

Bitrise/Storage/BRStorage.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#import <EasyMapping/EasyMapping.h>
1212

13+
#import "BRLogger.h"
1314
#import "NSArray+FRP.h"
1415
#import "BRMacro.h"
1516

@@ -197,7 +198,7 @@ - (BOOL)saveBuilds:(NSArray <BRBuildInfo *> *)buildsInfo forApp:(NSString *)appS
197198
}];
198199
result = [self saveContext:self.context error:error];
199200
} else {
200-
NSLog(@"Failed to save builds: %@", *error);
201+
BRLog(LL_WARN, LL_STORAGE, @"Failed to save builds: %@", *error);
201202
result = NO;
202203
}
203204

0 commit comments

Comments
 (0)