[google-toolbox-for-mac] r693 committed - Cache the verbosity level instead of fetching constantly.

60 views
Skip to first unread message

google-tool...@googlecode.com

unread,
Oct 29, 2014, 11:31:23 AM10/29/14
to google-tool...@googlegroups.com
Revision: 693
Author: thomasvl
Date: Wed Oct 29 15:30:57 2014 UTC
Log: Cache the verbosity level instead of fetching constantly.
https://code.google.com/p/google-toolbox-for-mac/source/detail?r=693

Modified:
/trunk/Foundation/GTMLogger.h
/trunk/Foundation/GTMLogger.m

=======================================
--- /trunk/Foundation/GTMLogger.h Fri Apr 20 18:30:11 2012 UTC
+++ /trunk/Foundation/GTMLogger.h Wed Oct 29 15:30:57 2014 UTC
@@ -454,7 +454,10 @@
// out of non-debug builds unless GTMVerboseLogging is set in the
environment or
// the processes's defaults. Messages at the kGTMLoggerLevelError level are
// never filtered.
-@interface GTMLogLevelFilter : NSObject <GTMLogFilter>
+@interface GTMLogLevelFilter : NSObject <GTMLogFilter> {
+ @private
+ BOOL verboseLoggingEnabled_;
+}
@end // GTMLogLevelFilter

// A simple log filter that does NOT filter anything out;
=======================================
--- /trunk/Foundation/GTMLogger.m Tue Feb 25 20:00:11 2014 UTC
+++ /trunk/Foundation/GTMLogger.m Wed Oct 29 15:30:57 2014 UTC
@@ -97,7 +97,7 @@

// Don't trust NSFileHandle not to throw
@try {
- GTMLogBasicFormatter *formatter = [[[GTMLogBasicFormatter alloc] init]
+ GTMLogBasicFormatter *formatter = [[[GTMLogBasicFormatter alloc] init]
autorelease];
GTMLogger *stdoutLogger =
[self loggerWithWriter:[NSFileHandle fileHandleWithStandardOutput]
@@ -475,9 +475,6 @@

@end // GTMLogStandardFormatter

-
-@implementation GTMLogLevelFilter
-
// Check the environment and the user preferences for the
GTMVerboseLogging key
// to see if verbose logging has been enabled. The environment variable
will
// override the defaults setting, so check the environment first.
@@ -501,6 +498,29 @@
return [[NSUserDefaults standardUserDefaults]
boolForKey:kVerboseLoggingKey];
}
// COV_NF_END
+
+@implementation GTMLogLevelFilter
+
+- (id)init {
+ self = [super init];
+ if (self) {
+ [[NSNotificationCenter defaultCenter] addObserver:self
+
selector:@selector(defaultsChanged:)
+
name:NSUserDefaultsDidChangeNotification
+ object:nil];
+
+ verboseLoggingEnabled_ = IsVerboseLoggingEnabled();
+ }
+
+ return self;
+}
+
+- (void)dealloc {
+ [[NSNotificationCenter defaultCenter] removeObserver:self
+
name:NSUserDefaultsDidChangeNotification
+ object:nil];
+ [super dealloc];
+}

// In DEBUG builds, log everything. If we're not in a debug build we'll
assume
// that we're in a Release build.
@@ -516,7 +536,7 @@
allow = NO;
break;
case kGTMLoggerLevelInfo:
- allow = IsVerboseLoggingEnabled();
+ allow = verboseLoggingEnabled_;
break;
case kGTMLoggerLevelError:
allow = YES;
@@ -531,6 +551,10 @@

return allow;
}
+
+- (void)defaultsChanged:(NSNotification *)note {
+ verboseLoggingEnabled_ = IsVerboseLoggingEnabled();
+}

@end // GTMLogLevelFilter

Reply all
Reply to author
Forward
0 new messages