Skip to content

Commit 5326872

Browse files
committed
ASL Logger cleanup and leaking
* Move ivar synthesis to the top of the implementation. * Add dealloc logic to avoid leaking asl_obj memory. * Add forced logic at the message level.
1 parent 907e6f9 commit 5326872

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

GoogleUtilities/Logger/Private/GULASLLogger.m

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ @interface GULASLLogger () {
4747

4848
@implementation GULASLLogger
4949

50+
@synthesize version = _version;
51+
@synthesize forcedDebug = _forcedDebug;
52+
5053
- (instancetype)init {
5154
self = [super init];
5255
if (self) {
@@ -95,8 +98,13 @@ - (void)initializeLogger {
9598
});
9699
}
97100

98-
@synthesize version = _version;
99-
@synthesize forcedDebug = _forcedDebug;
101+
- (void)dealloc {
102+
#pragma clang diagnostic push
103+
#pragma clang diagnostic ignored "-Wdeprecated-declarations" // asl is deprecated
104+
asl_release(self.aslClient);
105+
self.aslClient = nil;
106+
#pragma clang diagnostic pop
107+
}
100108

101109
- (void)setLogLevel:(GULLoggerLevel)logLevel {
102110
if (logLevel < GULLoggerLevelMin || logLevel > GULLoggerLevelMax) {
@@ -140,10 +148,12 @@ - (void)printToSTDERR {
140148

141149
- (void)logWithLevel:(GULLoggerLevel)level
142150
withService:(GULLoggerService)service
151+
isForced:(BOOL)forced
143152
withCode:(NSString *)messageCode
144153
withMessage:(NSString *)message, ... {
145154
[self initializeLogger];
146-
if (![self isLoggableLevel:level]) {
155+
// Skip logging this if the level isn't to be logged unless it's forced.
156+
if (![self isLoggableLevel:level] && !(self.forcedDebug || forced)) {
147157
return;
148158
}
149159

GoogleUtilities/Logger/Private/GULLoggerSystem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ typedef NSString *const GULLoggerService;
4343
/// Logs the given message.
4444
- (void)logWithLevel:(GULLoggerLevel)level
4545
withService:(GULLoggerService)service
46+
isForced:(BOOL)forced
4647
withCode:(NSString *)messageCode
4748
withMessage:(NSString *)message, ...;
4849
@end

0 commit comments

Comments
 (0)