Skip to content

Commit 52172d6

Browse files
committed
optional NSError on all log levels. change os log level mapping. remove info log level.
1 parent 5cfec76 commit 52172d6

26 files changed

+129
-132
lines changed

Branch-TestBed/Branch-SDK-Tests/BranchLoggerTests.m

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,33 @@ - (void)testLogLevelThresholdBlocksLowerLevels {
3535
}
3636
};
3737

38-
[logger logVerbose:@"This verbose message should not trigger the log callback."];
39-
[logger logDebug:@"This message should trigger the log callback."];
38+
[logger logVerbose:@"This verbose message should not trigger the log callback." error:nil];
39+
[logger logDebug:@"This message should trigger the log callback." error:nil];
4040

4141
[self waitForExpectationsWithTimeout:1 handler:nil];
4242
}
4343

4444
- (void)testLogCallbackExecutesWithCorrectParameters {
45-
XCTestExpectation *expectation = [self expectationWithDescription:@"Log callback expectation"];
46-
NSString *expectedMessage = @"[BranchSDK][Info][BranchLoggerTests testLogCallbackExecutesWithCorrectParameters] Test message";
47-
BranchLogLevel expectedLevel = BranchLogLevelInfo;
48-
49-
BranchLogger *logger = [BranchLogger new];
50-
51-
logger.logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) {
52-
XCTAssertEqualObjects(message, expectedMessage, "Logged message does not match expected message.");
53-
XCTAssertEqual(logLevel, expectedLevel, "Logged level does not match expected level.");
54-
XCTAssertNil(error, "Error should be nil.");
55-
[expectation fulfill];
56-
};
45+
// TODO: replace this test as info has been removed
5746

58-
logger.loggingEnabled = YES;
59-
logger.logLevelThreshold = BranchLogLevelInfo;
60-
[logger logInfo:@"Test message"];
61-
62-
[self waitForExpectationsWithTimeout:1 handler:nil];
47+
// XCTestExpectation *expectation = [self expectationWithDescription:@"Log callback expectation"];
48+
// NSString *expectedMessage = @"[BranchSDK][Info][BranchLoggerTests testLogCallbackExecutesWithCorrectParameters] Test message";
49+
// BranchLogLevel expectedLevel = BranchLogLevelInfo;
50+
//
51+
// BranchLogger *logger = [BranchLogger new];
52+
//
53+
// logger.logCallback = ^(NSString * _Nonnull message, BranchLogLevel logLevel, NSError * _Nullable error) {
54+
// XCTAssertEqualObjects(message, expectedMessage, "Logged message does not match expected message.");
55+
// XCTAssertEqual(logLevel, expectedLevel, "Logged level does not match expected level.");
56+
// XCTAssertNil(error, "Error should be nil.");
57+
// [expectation fulfill];
58+
// };
59+
//
60+
// logger.loggingEnabled = YES;
61+
// logger.logLevelThreshold = BranchLogLevelInfo;
62+
// [logger logInfo:@"Test message"];
63+
//
64+
// [self waitForExpectationsWithTimeout:1 handler:nil];
6365
}
6466

6567
- (void)testLogLevelSpecificityFiltersLowerLevels {
@@ -81,7 +83,7 @@ - (void)testLogLevelSpecificityFiltersLowerLevels {
8183
callbackCount++;
8284
};
8385

84-
[logger logVerbose:@"This should not be logged due to log level threshold."];
86+
[logger logVerbose:@"This should not be logged due to log level threshold." error:nil];
8587
[logger logError:@"This should be logged" error:nil];
8688

8789
[self waitForExpectations:@[verboseExpectation, errorExpectation] timeout:2];

Sources/BranchSDK/BNCApplication.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ + (NSDate *) currentInstallDate {
125125
#endif
126126

127127
if (installDate == nil || [installDate timeIntervalSince1970] <= 0.0) {
128-
[[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Invalid install date, using [NSDate date]."]];
128+
[[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Invalid install date, using [NSDate date]."] error:nil];
129129
}
130130
return installDate;
131131
}

Sources/BranchSDK/BNCEncodingUtils.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ + (NSString *)encodeDictionaryToJsonString:(NSDictionary *)dictionary {
230230

231231
[encodedDictionary appendString:@"}"];
232232

233-
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Encoded dictionary: %@.", encodedDictionary]];
233+
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Encoded dictionary: %@.", encodedDictionary] error:nil];
234234
return encodedDictionary;
235235
}
236236

@@ -290,7 +290,7 @@ + (NSString *)encodeArrayToJsonString:(NSArray *)array {
290290
[encodedArray deleteCharactersInRange:NSMakeRange([encodedArray length] - 1, 1)];
291291
[encodedArray appendString:@"]"];
292292

293-
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Encoded array: %@.", encodedArray]];
293+
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Encoded array: %@.", encodedArray] error:nil];
294294

295295
return encodedArray;
296296
}

Sources/BranchSDK/BNCKeyChain.m

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ + (NSDate *) retrieveDateForService:(NSString *)service key:(NSString *)key erro
5757
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)dictionary, (CFTypeRef *)&valueData);
5858
if (status != errSecSuccess) {
5959
NSError *localError = [self errorWithKey:key OSStatus:status];
60-
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Can't retrieve key: %@.", localError]];
60+
[[BranchLogger shared] logDebug:@"Can't retrieve key" error:localError];
6161
if (error) *error = localError;
6262
if (valueData) CFRelease(valueData);
6363
return nil;
@@ -106,7 +106,7 @@ + (NSError *) storeDate:(NSDate *)date
106106
OSStatus status = SecItemDelete((__bridge CFDictionaryRef)dictionary);
107107
if (status != errSecSuccess && status != errSecItemNotFound) {
108108
NSError *error = [self errorWithKey:key OSStatus:status];
109-
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Can't clear to store key: %@.", error]];
109+
[[BranchLogger shared] logDebug:@"Can't clear to store key" error:error];
110110
}
111111

112112
dictionary[(__bridge id)kSecValueData] = valueData;
@@ -122,7 +122,7 @@ + (NSError *) storeDate:(NSDate *)date
122122
status = SecItemAdd((__bridge CFDictionaryRef)dictionary, NULL);
123123
if (status) {
124124
NSError *error = [self errorWithKey:key OSStatus:status];
125-
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Can't store key: %@.", error]];
125+
[[BranchLogger shared] logDebug:@"Can't store key" error:error];
126126
return error;
127127
}
128128
return nil;
@@ -140,7 +140,7 @@ + (NSError*) removeValuesForService:(NSString *)service key:(NSString *)key {
140140
if (status == errSecItemNotFound) status = errSecSuccess;
141141
if (status) {
142142
NSError *error = [self errorWithKey:key OSStatus:status];
143-
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Can't remove key: %@.", error]];
143+
[[BranchLogger shared] logDebug:@"Can't remove key" error:error];
144144
return error;
145145
}
146146
return nil;
@@ -154,7 +154,9 @@ + (NSString * _Nullable) securityAccessGroup {
154154

155155
// First store a value:
156156
NSError *error = [self storeDate:[NSDate date] forService:@"BranchKeychainService" key:@"Temp" cloudAccessGroup:nil];
157-
if (error) [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Error storing temp value: %@.", error]];
157+
if (error) {
158+
[[BranchLogger shared] logDebug:@"Error storing temp value" error:error];
159+
}
158160

159161
NSDictionary* dictionary = @{
160162
(__bridge id)kSecClass: (__bridge id)kSecClassGenericPassword,
@@ -167,8 +169,7 @@ + (NSString * _Nullable) securityAccessGroup {
167169
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)dictionary, (CFTypeRef*)&resultDictionary);
168170
if (status == errSecItemNotFound) return nil;
169171
if (status != errSecSuccess) {
170-
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Get securityAccessGroup returned(%ld): %@.",
171-
(long) status, [self errorWithKey:nil OSStatus:status]]];
172+
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Get securityAccessGroup returned(%ld): %@.", (long) status, [self errorWithKey:nil OSStatus:status]] error:nil];
172173
return nil;
173174
}
174175
NSString*group =

Sources/BranchSDK/BNCNetworkService.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,14 @@ - (void) startOperation:(BNCNetworkOperation*)operation {
197197
[[NSDate date] timeIntervalSinceDate:operation.startDate],
198198
(long)operation.response.statusCode,
199199
operation.error,
200-
operation.stringFromResponseData]];
200+
operation.stringFromResponseData] error:nil];
201201
}
202-
if (operation.completionBlock)
202+
if (operation.completionBlock) {
203203
operation.completionBlock(operation);
204+
}
204205
}];
205206

206-
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Network start operation %@.", operation.request.URL]];
207+
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Network start operation %@.", operation.request.URL] error:nil];
207208

208209
[operation.sessionTask resume];
209210
}

Sources/BranchSDK/BNCPartnerParameters.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ - (void)addFacebookParameterWithName:(NSString *)name value:(NSString *)value {
5454
if ([self sha256HashSanityCheckValue:value]) {
5555
[self addParameterWithName:name value:value partnerName:@"fb"];
5656
} else {
57-
[[BranchLogger shared] logWarning:@"Partner parameter does not appear to be SHA256 hashed. Dropping the parameter."];
57+
[[BranchLogger shared] logWarning:@"Partner parameter does not appear to be SHA256 hashed. Dropping the parameter." error:nil];
5858
}
5959
}
6060

6161
- (void)addSnapParameterWithName:(NSString *)name value:(NSString *)value {
6262
if ([self sha256HashSanityCheckValue:value]) {
6363
[self addParameterWithName:name value:value partnerName:@"snap"];
6464
} else {
65-
[[BranchLogger shared] logWarning:@"Partner parameter does not appear to be SHA256 hashed. Dropping the parameter."];
65+
[[BranchLogger shared] logWarning:@"Partner parameter does not appear to be SHA256 hashed. Dropping the parameter." error:nil];
6666
}
6767
}
6868

Sources/BranchSDK/BNCPreferenceHelper.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ - (void)setPatternListURL:(NSString *)url {
168168
[self writeObjectToDefaults:BRANCH_PREFS_KEY_PATTERN_LIST_URL value:url];
169169
}
170170
} else {
171-
[[BranchLogger shared] logWarning:@"Ignoring invalid custom CDN URL"];
171+
[[BranchLogger shared] logWarning:@"Ignoring invalid custom CDN URL" error:nil];
172172
}
173173
}
174174

@@ -923,7 +923,7 @@ - (void)persistPrefsToDisk {
923923
NSError *error = nil;
924924
[data writeToURL:prefsURL options:NSDataWritingAtomic error:&error];
925925
if (error) {
926-
[[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Failed to persist preferences: %@.", error]];
926+
[[BranchLogger shared] logWarning:@"Failed to persist preferences" error:error];
927927
}
928928
}];
929929
[_persistPrefsQueue addOperation:newPersistOp];
@@ -938,7 +938,7 @@ - (NSData *)serializePrefDict:(NSMutableDictionary *)dict {
938938
@try {
939939
data = [NSKeyedArchiver archivedDataWithRootObject:dict requiringSecureCoding:YES error:NULL];
940940
} @catch (id exception) {
941-
[[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Exception serializing preferences dict: %@.", exception]];
941+
[[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Exception serializing preferences dict: %@.", exception] error:nil];
942942
}
943943
return data;
944944
}
@@ -969,10 +969,10 @@ - (NSData *)loadPrefData {
969969
NSError *error = nil;
970970
data = [NSData dataWithContentsOfURL:self.class.URLForPrefsFile options:0 error:&error];
971971
if (error || !data) {
972-
[[BranchLogger shared] logWarning:@"Failed to load preferences from storage."];
972+
[[BranchLogger shared] logWarning:@"Failed to load preferences from storage." error:error];
973973
}
974974
} @catch (NSException *) {
975-
[[BranchLogger shared] logWarning:@"Failed to load preferences from storage."];
975+
[[BranchLogger shared] logWarning:@"Failed to load preferences from storage." error:nil];
976976
}
977977
return data;
978978
}
@@ -985,7 +985,7 @@ - (NSMutableDictionary *)deserializePrefDictFromData:(NSData *)data {
985985

986986
dict = [NSKeyedUnarchiver unarchivedObjectOfClasses:classes fromData:data error:&error];
987987
if (error) {
988-
[[BranchLogger shared] logWarning:@"Failed to load preferences from storage."];
988+
[[BranchLogger shared] logWarning:@"Failed to load preferences from storage." error:error];
989989
}
990990
}
991991

Sources/BranchSDK/BNCReferringURLUtility.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ - (void)checkForAndMigrateOldGbraid {
286286
self.preferenceHelper.referrerGBRAIDValidityWindow = 0;
287287
self.preferenceHelper.referrerGBRAIDInitDate = nil;
288288

289-
[[BranchLogger shared] logDebug:@"Updated old Gbraid to new BNCUrlQueryParameter"];
289+
[[BranchLogger shared] logDebug:@"Updated old Gbraid to new BNCUrlQueryParameter" error:nil];
290290
}
291291
}
292292

Sources/BranchSDK/BNCSKAdNetwork.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ - (BOOL)shouldAttemptSKAdNetworkCallout {
7373
- (void)registerAppForAdNetworkAttribution {
7474
if (@available(iOS 14.0, macCatalyst 14.0, *)) {
7575
if ([self shouldAttemptSKAdNetworkCallout] && [self.skAdNetworkClass respondsToSelector:self.skAdNetworkRegisterAppForAdNetworkAttribution]) {
76-
[[BranchLogger shared] logDebug:@"Calling registerAppForAdNetworkAttribution"];
76+
[[BranchLogger shared] logDebug:@"Calling registerAppForAdNetworkAttribution" error:nil];
7777
// Equivalent call [SKAdNetwork registerAppForAdNetworkAttribution];
7878
((id (*)(id, SEL))[self.skAdNetworkClass methodForSelector:self.skAdNetworkRegisterAppForAdNetworkAttribution])(self.skAdNetworkClass, self.skAdNetworkRegisterAppForAdNetworkAttribution);
7979
}
@@ -83,7 +83,7 @@ - (void)registerAppForAdNetworkAttribution {
8383
- (void)updateConversionValue:(NSInteger)conversionValue {
8484
if (@available(iOS 14.0, macCatalyst 14.0, *)) {
8585
if ([self shouldAttemptSKAdNetworkCallout] && [self.skAdNetworkClass respondsToSelector:self.skAdNetworkUpdateConversionValue]) {
86-
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Calling updateConversionValue:%ld", (long)conversionValue]];
86+
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Calling updateConversionValue:%ld", (long)conversionValue] error:nil];
8787

8888
// Equivalent call [SKAdNetwork updateConversionValue:conversionValue];
8989
((id (*)(id, SEL, NSInteger))[self.skAdNetworkClass methodForSelector:self.skAdNetworkUpdateConversionValue])(self.skAdNetworkClass, self.skAdNetworkUpdateConversionValue, conversionValue);
@@ -94,7 +94,7 @@ - (void)updateConversionValue:(NSInteger)conversionValue {
9494
- (void)updatePostbackConversionValue:(NSInteger)conversionValue completionHandler:(void (^)(NSError *error))completion {
9595
if (@available(iOS 15.4, macCatalyst 15.4, *)) {
9696
if ([self shouldAttemptSKAdNetworkCallout] && [self.skAdNetworkClass respondsToSelector:self.skAdNetworkUpdatePostbackConversionValue]) {
97-
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Calling updatePostbackConversionValue:%ld completionHandler:completion", (long)conversionValue]];
97+
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Calling updatePostbackConversionValue:%ld completionHandler:completion", (long)conversionValue] error:nil];
9898

9999
// Equivalent call [SKAdNetwork updatePostbackConversionValue:completionHandler:];
100100
((id (*)(id, SEL, NSInteger,void (^)(NSError *error)))[self.skAdNetworkClass methodForSelector:self.skAdNetworkUpdatePostbackConversionValue])(self.skAdNetworkClass, self.skAdNetworkUpdatePostbackConversionValue, conversionValue, completion);
@@ -109,7 +109,7 @@ - (void)updatePostbackConversionValue:(NSInteger)fineValue
109109
completionHandler:(void (^)(NSError *error))completion {
110110
if (@available(iOS 16.1, macCatalyst 16.1, *)) {
111111
if ([self shouldAttemptSKAdNetworkCallout] && [self.skAdNetworkClass respondsToSelector:self.skAdNetworkUpdatePostbackConversionValueCoarseValueLockWindow]) {
112-
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Calling updatePostbackConversionValue:%ld coarseValue:%@ lockWindow:%d completionHandler:completion", (long)fineValue, coarseValue, lockWindow]];
112+
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Calling updatePostbackConversionValue:%ld coarseValue:%@ lockWindow:%d completionHandler:completion", (long)fineValue, coarseValue, lockWindow] error:nil];
113113
// Equivalent call [SKAdNetwork updatePostbackConversionValue:coarseValue:lockWindow:completionHandler:];
114114
((id (*)(id, SEL, NSInteger, NSString *, BOOL, void (^)(NSError *error)))[self.skAdNetworkClass methodForSelector:self.skAdNetworkUpdatePostbackConversionValueCoarseValueLockWindow])(self.skAdNetworkClass, self.skAdNetworkUpdatePostbackConversionValueCoarseValueLockWindow, fineValue, coarseValue, lockWindow, completion);
115115
}

Sources/BranchSDK/BNCServerInterface.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ - (void)genericHTTPRequest:(NSURLRequest *)request retryNumber:(NSInteger)retryN
118118
dispatch_time(DISPATCH_TIME_NOW, self.preferenceHelper.retryInterval * NSEC_PER_SEC);
119119
dispatch_after(dispatchTime, dispatch_get_main_queue(), ^{
120120
if (retryHandler) {
121-
[[BranchLogger shared] logDebug: [NSString stringWithFormat:@"Retrying request with url %@", request.URL.relativePath]];
121+
[[BranchLogger shared] logDebug: [NSString stringWithFormat:@"Retrying request with url %@", request.URL.relativePath] error:nil];
122122
// Create the next request
123123
NSURLRequest *retryRequest = retryHandler(retryNumber);
124124
[self genericHTTPRequest:retryRequest
@@ -170,7 +170,7 @@ - (void)genericHTTPRequest:(NSURLRequest *)request retryNumber:(NSInteger)retryN
170170
if (![self isLinkingRelatedRequest:endpoint]) {
171171
[[BNCPreferenceHelper sharedInstance] clearTrackingInformation];
172172
NSError *error = [NSError branchErrorWithCode:BNCTrackingDisabledError];
173-
[[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Dropping Request %@: - %@", endpoint, error]];
173+
[[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Dropping Request %@: - %@", endpoint, error] error:nil];
174174
if (callback) {
175175
callback(nil, error);
176176
}
@@ -278,7 +278,7 @@ - (NSURLRequest *)prepareGetRequest:(NSDictionary *)params url:(NSString *)url k
278278

279279
NSDictionary *tmp = [self addRetryCount:retryNumber toJSON:params];
280280
NSString *requestUrlString = [NSString stringWithFormat:@"%@%@", url, [BNCEncodingUtils encodeDictionaryToQueryString:tmp]];
281-
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"URL: %@", requestUrlString]];
281+
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"URL: %@", requestUrlString] error:nil];
282282
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:requestUrlString]
283283
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
284284
timeoutInterval:self.preferenceHelper.timeout];
@@ -295,10 +295,10 @@ - (NSURLRequest *)preparePostRequest:(NSDictionary *)params url:(NSString *)url
295295
NSData *postData = [BNCEncodingUtils encodeDictionaryToJsonData:tmp];
296296
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
297297

298-
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"URL: %@.\n", url]];
298+
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"URL: %@.\n", url] error:nil];
299299
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Body: %@\nJSON: %@.",
300300
params,
301-
[[NSString alloc] initWithData:postData encoding:NSUTF8StringEncoding]]];
301+
[[NSString alloc] initWithData:postData encoding:NSUTF8StringEncoding]] error:nil];
302302

303303
NSMutableURLRequest *request =
304304
[NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
@@ -328,7 +328,7 @@ - (BNCServerResponse *)processServerResponse:(NSURLResponse *)response data:(NSD
328328
serverResponse.requestId = requestId;
329329
}
330330

331-
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Server returned: %@.", serverResponse]];
331+
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Server returned: %@.", serverResponse] error:nil];
332332

333333
return serverResponse;
334334
}

0 commit comments

Comments
 (0)