Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for crash caused by persistent logging #321

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions RadarSDK/Radar.m
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ + (void)logBackgrounding {
}

+ (void)logResigningActive {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug type:RadarLogTypeNone message:@"App resigning active" includeDate:YES includeBattery:YES];
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelInfo type:RadarLogTypeNone message:@"App resigning active" includeDate:YES includeBattery:YES append:YES];
}


Expand Down Expand Up @@ -1324,11 +1324,9 @@ + (void)flushLogs {

[[RadarAPIClient sharedInstance] syncLogs:flushableLogs
completionHandler:^(RadarStatus status) {
if (onComplete) {
[RadarUtils runOnMainThread:^{
onComplete(status);
}];
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
onComplete(status);
});
}];
}

Expand Down
14 changes: 12 additions & 2 deletions RadarSDK/RadarLogBuffer.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,18 @@ - (void)persistLogs {
- (NSArray<NSString *> *)getLogFilesInTimeOrder {
NSString *characterToStrip = @"_";
NSComparator compareTimeStamps = ^NSComparisonResult(NSString *str1, NSString *str2) {
return [@([[str1 stringByReplacingOccurrencesOfString:characterToStrip withString:@""] integerValue])
compare:@([[str2 stringByReplacingOccurrencesOfString:characterToStrip withString:@""] integerValue])];
NSArray<NSString *> *parts1 = [str1 componentsSeparatedByString:characterToStrip];
NSArray<NSString *> *parts2 = [str2 componentsSeparatedByString:characterToStrip];

// Compare timestamps
NSComparisonResult result = [@([parts1[0] longLongValue]) compare:@([parts2[0] longLongValue])];

// If timestamps are equal, compare file counters
if (result == NSOrderedSame) {
result = [@([parts1[1] intValue]) compare:@([parts2[1] intValue])];
}

return result;
};

return [self.fileHandler sortedFilesInDirectory:self.logFileDir usingComparator:compareTimeStamps];
Expand Down
6 changes: 4 additions & 2 deletions RadarSDK/RadarLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ - (void)logWithLevel:(RadarLogLevel)level type:(RadarLogType)type message:(NSStr
if (append) {
[[RadarLogBuffer sharedInstance] write:level type:type message:message forcePersist:YES];
} else {
dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[Radar sendLog:level type:type message:message];

NSString *log = [NSString stringWithFormat:@"%@ | backgroundTimeRemaining = %g", message, [RadarUtils backgroundTimeRemaining]];

os_log(OS_LOG_DEFAULT, "%@", log);

[[RadarDelegateHolder sharedInstance] didLogMessage:log];
dispatch_async(dispatch_get_main_queue(), ^{
[[RadarDelegateHolder sharedInstance] didLogMessage:log];
});
});
}
}
Expand Down
Loading