Skip to content

Commit

Permalink
Fix memory consumption bug
Browse files Browse the repository at this point in the history
Fix memory consumption bug
  • Loading branch information
funkyboy authored Mar 16, 2018
2 parents 4092e2b + 02c022f commit 2b9e6a7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 32 deletions.
70 changes: 42 additions & 28 deletions Source/ARTLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -186,53 +186,67 @@ - (ARTLog *)errorMode {
}

- (void)verbose:(NSString *)format, ... {
va_list args;
va_start(args, format);
[self log:[[NSString alloc] initWithFormat:format arguments:args] level:ARTLogLevelVerbose];
va_end(args);
if (self.logLevel <= ARTLogLevelVerbose) {
va_list args;
va_start(args, format);
[self log:[[NSString alloc] initWithFormat:format arguments:args] level:ARTLogLevelVerbose];
va_end(args);
}
}


- (void)verbose:(const char *)fileName line:(NSUInteger)line message:(NSString *)message, ... {
va_list args;
va_start(args, message);
[self log:[[NSString alloc] initWithFormat:[NSString stringWithFormat:@"(%@:%lu) %@", [[NSString stringWithUTF8String:fileName] lastPathComponent], (unsigned long)line, message] arguments:args] level:ARTLogLevelVerbose];
va_end(args);
if (self.logLevel <= ARTLogLevelVerbose) {
va_list args;
va_start(args, message);
[self log:[[NSString alloc] initWithFormat:[NSString stringWithFormat:@"(%@:%lu) %@", [[NSString stringWithUTF8String:fileName] lastPathComponent], (unsigned long)line, message] arguments:args] level:ARTLogLevelVerbose];
va_end(args);
}
}

- (void)debug:(NSString *)format, ... {
va_list args;
va_start(args, format);
[self log:[[NSString alloc] initWithFormat:format arguments:args] level:ARTLogLevelDebug];
va_end(args);
if (self.logLevel <= ARTLogLevelDebug) {
va_list args;
va_start(args, format);
[self log:[[NSString alloc] initWithFormat:format arguments:args] level:ARTLogLevelDebug];
va_end(args);
}
}

- (void)debug:(const char *)fileName line:(NSUInteger)line message:(NSString *)message, ... {
va_list args;
va_start(args, message);
[self log:[[NSString alloc] initWithFormat:[NSString stringWithFormat:@"(%@:%lu) %@", [[NSString stringWithUTF8String:fileName] lastPathComponent], (unsigned long)line, message] arguments:args] level:ARTLogLevelDebug];
va_end(args);
if (self.logLevel <= ARTLogLevelDebug) {
va_list args;
va_start(args, message);
[self log:[[NSString alloc] initWithFormat:[NSString stringWithFormat:@"(%@:%lu) %@", [[NSString stringWithUTF8String:fileName] lastPathComponent], (unsigned long)line, message] arguments:args] level:ARTLogLevelDebug];
va_end(args);
}
}

- (void)info:(NSString *)format, ... {
va_list args;
va_start(args, format);
[self log:[[NSString alloc] initWithFormat:format arguments:args] level:ARTLogLevelInfo];
va_end(args);
if (self.logLevel <= ARTLogLevelInfo) {
va_list args;
va_start(args, format);
[self log:[[NSString alloc] initWithFormat:format arguments:args] level:ARTLogLevelInfo];
va_end(args);
}
}

- (void)warn:(NSString *)format, ... {
va_list args;
va_start(args, format);
[self log:[[NSString alloc] initWithFormat:format arguments:args] level:ARTLogLevelWarn];
va_end(args);
if (self.logLevel <= ARTLogLevelWarn) {
va_list args;
va_start(args, format);
[self log:[[NSString alloc] initWithFormat:format arguments:args] level:ARTLogLevelWarn];
va_end(args);
}
}

- (void)error:(NSString *)format, ... {
va_list args;
va_start(args, format);
[self log:[[NSString alloc] initWithFormat:format arguments:args] level:ARTLogLevelError];
va_end(args);
if (self.logLevel <= ARTLogLevelError) {
va_list args;
va_start(args, format);
[self log:[[NSString alloc] initWithFormat:format arguments:args] level:ARTLogLevelError];
va_end(args);
}
}

- (void)log:(NSString *)message withLevel:(ARTLogLevel)level {
Expand Down
18 changes: 14 additions & 4 deletions Source/ARTNSDate+ARTUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,20 @@ - (NSInteger)artToIntegerMs {
}

- (NSString *)toSentryTimestamp {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss'.'SS";
dateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
return [dateFormatter stringFromDate:self];
return [[[self class] customDateFormatter] stringFromDate:self];
}

+ (NSDateFormatter *)customDateFormatter {
static dispatch_once_t onceToken;
static NSDateFormatter *customDateFormatter;
dispatch_once(&onceToken, ^{
customDateFormatter = [[NSDateFormatter alloc] init];
customDateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss'.'SS";
customDateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
});
return customDateFormatter;
}



@end
1 change: 1 addition & 0 deletions Spec/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ class Utilities: QuickSpec {
it("should have a history of logs") {
let options = AblyTests.commonAppSetup()
let realtime = ARTRealtime(options: options)
realtime.logger.logLevel = .verbose
defer { realtime.close() }
let channel = realtime.channels.get("foo")

Expand Down

0 comments on commit 2b9e6a7

Please sign in to comment.