Commits

Tuukka Norri committed f4f6f46

Fixed logger configuration and database script
- Roles now get dropped within the same transaction as they are created.
- Logger configuration is now synchronized.
- Also logger default level now actually gets set for debug builds.

  • Participants
  • Parent commits 0d71552
  • Branches PGTS

Comments (0)

Files changed (6)

Framework/Contrib/Log4Cocoa/L4Configurator.h

 + (void) resetLineBreakChar;
 + (NSData *) lineBreakChar;
 
-+ (void) parseConfiguration: (NSDictionary *) dict logger: (L4Logger *) logger;
 + (NSString *) configurationFilePath;
 
 @end

Framework/Contrib/Log4Cocoa/L4Configurator.m

 NSString* const L4ConfigurationFilePath = @"L4ConfigurationFilePath";
 NSString* const L4ConfigurationFileName = @"Log4CocoaConfiguration";
 
-static NSData *lineBreakChar;
+static NSData *lineBreakChar = nil;
+static NSRecursiveLock *configurationLock = nil;
+static volatile BOOL haveConfiguration = NO;
 
 @implementation L4Configurator
 
 + (void) initialize
 {
-    // Making sure that we capture the startup time of
-    // this application.  This sanity check is also in
-    // +[L4Logger initialize] too.
-    //
-    [L4LoggingEvent startTime];
+	static BOOL tooLate = NO;
+	if (NO == tooLate)
+	{
+		tooLate = YES;
+		
+		// Making sure that we capture the startup time of
+		// this application.  This sanity check is also in
+		// +[L4Logger initialize] too.
+		//
+		[L4LoggingEvent startTime];
+		
+		configurationLock = [[NSRecursiveLock alloc] init];
+	}
 }
 
 + (void) basicConfiguration
 {
-    L4Logger* rootLogger = [L4Logger rootLogger];
-    id appender = [[[L4ConsoleAppender alloc] initStandardOutWithLayout: [L4Layout simpleLayout]] autorelease];
-    [rootLogger addAppender: appender];
-#if BUILD_CONFIGURATION == Release
-    [rootLogger setLevel: [L4Level error]];
+	[configurationLock lock];
+	if (NO == haveConfiguration)
+	{
+		L4Logger* rootLogger = [L4Logger rootLogger];
+		id appender = [[[L4ConsoleAppender alloc] initStandardOutWithLayout: [L4Layout simpleLayout]] autorelease];
+		[rootLogger addAppender: appender];
+#if defined(RELEASE_BUILD)
+		[rootLogger setLevel: [L4Level error]];
 #else
-    [rootLogger setLevel: [L4Level info]];
+		[rootLogger setLevel: [L4Level info]];
 #endif
+		
+		haveConfiguration = YES;
+	}
+	[configurationLock unlock];
 }
 
 + (void) autoConfigure
 {
-    // [[NSFileManager defaultManager] currentDirectoryPath];
-    NSString* path = [self configurationFilePath];
-    if (nil == path)
-        [self basicConfiguration];
-    else
-    {
-        L4Logger* rootLogger = [L4Logger rootLogger];
-        NSDictionary* configuration = [NSDictionary dictionaryWithContentsOfFile: path];
-        [self parseConfiguration: [configuration objectForKey: @"DefaultConfiguration"] logger: rootLogger];
-        
-        //Add a basic appender in case one wasn't configured
-        if (0 < [[rootLogger allAppendersArray] count])
-            [self basicConfiguration];
-        
-        NSEnumerator* e = nil;
-        id currentKey = nil;
-        NSDictionary* dict = nil;
-        
-        {
-            dict = [configuration objectForKey: @"ConfigurationByClass"];
-            e = [dict keyEnumerator];
-            while ((currentKey = [e nextObject]))
-            {
-                L4Logger* logger = [L4Logger loggerForClass: NSClassFromString (currentKey)];
-                [self parseConfiguration: [dict objectForKey: currentKey] logger: logger];
-            }
-        }
-        
-        {
-            dict = [configuration objectForKey: @"ConfigurationByName"];
-            e = [dict keyEnumerator];
-            while ((currentKey = [e nextObject]))
-            {
-                L4Logger* logger = [L4Logger loggerForName: currentKey];
-                [self parseConfiguration: [dict objectForKey: currentKey] logger: logger];
-            }
-        }
-    }
-}
-
-+ (void) parseConfiguration: (NSDictionary *) dict logger: (L4Logger *) logger
-{
-    //Set the level
-    NSString* level = [dict objectForKey: @"Level"];
-    SEL levelSelector = NSSelectorFromString (level);
-    if (NULL == levelSelector)
-    {
-#if BUILD_CONFIGURATION == Release
-        levelSelector = @selector (error);
-#else
-        levelSelector = @selector (info);
-#endif
-    }
-    [logger setLevel: [L4Level performSelector: levelSelector]];
+	[configurationLock lock];
+	if (NO == haveConfiguration)
+	{		
+		// [[NSFileManager defaultManager] currentDirectoryPath];
+		NSString* path = [self configurationFilePath];
+		if (nil == path)
+			[self basicConfiguration];
+		else
+		{
+			L4Logger* rootLogger = [L4Logger rootLogger];
+			NSDictionary* configuration = [NSDictionary dictionaryWithContentsOfFile: path];
+			[rootLogger parseConfiguration: [configuration objectForKey: @"DefaultConfiguration"]];
+			
+			//Add a basic appender in case one wasn't configured
+			if (0 < [[rootLogger allAppendersArray] count])
+				[self basicConfiguration];
+			
+			NSEnumerator* e = nil;
+			id currentKey = nil;
+			NSDictionary* dict = nil;
+			
+			{
+				dict = [configuration objectForKey: @"ConfigurationByClass"];
+				e = [dict keyEnumerator];
+				while ((currentKey = [e nextObject]))
+				{
+					L4Logger* logger = [L4Logger loggerForClass: NSClassFromString (currentKey)];
+					[logger parseConfiguration: [dict objectForKey: currentKey]];
+				}
+			}
+			
+			{
+				dict = [configuration objectForKey: @"ConfigurationByName"];
+				e = [dict keyEnumerator];
+				while ((currentKey = [e nextObject]))
+				{
+					L4Logger* logger = [L4Logger loggerForName: currentKey];
+					[logger parseConfiguration: [dict objectForKey: currentKey]];
+				}
+			}
+		}
+		haveConfiguration = YES;
+	}
+	[configurationLock unlock];
 }
 
 /**

Framework/Contrib/Log4Cocoa/L4Logger.h

 - (L4Level *) level;
 - (void) setLevel: (L4Level *) aLevel; // nil is ok, because then we just pick up the parent's level
 
+- (void) parseConfiguration: (NSDictionary *) dict;
 @end
 
 @interface L4Logger (AppenderRelatedMethods)

Framework/Contrib/Log4Cocoa/L4Logger.m

     [super dealloc];
 }
 
+- (void) parseConfiguration: (NSDictionary *) dict
+{
+    //Set the level
+    NSString* aLevel = [dict objectForKey: @"Level"];
+    SEL levelSelector = NSSelectorFromString (aLevel);
+    if (NULL == levelSelector)
+    {
+#if BUILD_CONFIGURATION == Release
+        levelSelector = @selector (error);
+#else
+        levelSelector = @selector (info);
+#endif
+    }
+    [self setLevel: [L4Level performSelector: levelSelector]];
+}
+
 - (BOOL) additivity
 {
     return additive;

Framework/Contrib/Log4Cocoa/Log4Cocoa.xcodeproj/project.pbxproj

 		530EBD130B4BBFAE00DFC1CA /* Info-Log4Cocoa__Upgraded_.plist */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "Info-Log4Cocoa__Upgraded_.plist"; sourceTree = "<group>"; };
 		530EBD140B4BBFAE00DFC1CA /* Log4Cocoa.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Log4Cocoa.framework; sourceTree = BUILT_PRODUCTS_DIR; };
 		530EC0030B4BCDB100DFC1CA /* libLog4Cocoa.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libLog4Cocoa.a; sourceTree = BUILT_PRODUCTS_DIR; };
-		53C1DF180B4BD429007947D8 /* AllTests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = AllTests; sourceTree = BUILT_PRODUCTS_DIR; };
+		53C1DF180B4BD429007947D8 /* AllTests */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = AllTests; sourceTree = BUILT_PRODUCTS_DIR; };
 		53C1DF1F0B4BD429007947D8 /* Documentation */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Documentation; sourceTree = BUILT_PRODUCTS_DIR; };
 		C4965D2F0465C75A0065302B /* AllTests_Prefix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AllTests_Prefix.h; sourceTree = "<group>"; };
 		C4965D320465C7B30065302B /* ObjcUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = file; name = ObjcUnit.framework; path = /Library/Frameworks/ObjcUnit.framework; sourceTree = "<absolute>"; };
 				GCC_OPTIMIZATION_LEVEL = 0;
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/Foundation.framework/Headers/Foundation.h";
+				GCC_TREAT_WARNINGS_AS_ERRORS = YES;
 				INSTALL_PATH = "";
 				OTHER_LDFLAGS = (
 					"-framework",
 				PRIVATE_HEADERS_FOLDER_PATH = Log4Cocoa;
 				PRODUCT_NAME = Log4Cocoa;
 				PUBLIC_HEADERS_FOLDER_PATH = Log4Cocoa;
+				WARNING_CFLAGS = "-Wall";
 				ZERO_LINK = YES;
 			};
 			name = Debug;
 				GCC_MODEL_TUNING = G4;
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/Foundation.framework/Headers/Foundation.h";
+				GCC_PREPROCESSOR_DEFINITIONS = RELEASE_BUILD;
+				GCC_TREAT_WARNINGS_AS_ERRORS = YES;
 				INSTALL_PATH = "";
 				OTHER_LDFLAGS = (
 					"-framework",
 				PRIVATE_HEADERS_FOLDER_PATH = Log4Cocoa;
 				PRODUCT_NAME = Log4Cocoa;
 				PUBLIC_HEADERS_FOLDER_PATH = Log4Cocoa;
+				WARNING_CFLAGS = "-Wall";
 				ZERO_LINK = NO;
 			};
 			name = Release;

Framework/Sources/PGTSConnectionPrivate.m

 
 - (void) logNotice: (id) anObject
 {
-    log4Info (@"(%p) NOTICE: %@", self, anObject);
+    log4Info (@"(%p) %@", self, anObject);
 }
 
 - (void) logNotification: (id) anObject