svn rev #22058: tools/gssmonger/trunk/gssmaster/

raeburn@MIT.EDU raeburn at MIT.EDU
Thu Feb 26 15:35:29 EST 2009


http://src.mit.edu/fisheye/changelog/krb5/?cs=22058
Commit By: raeburn
Log Message:
Implement block hierarchy, so when we close one logging block we pop
back to its parent, instead of having to create a fresh one for the
next logged message.



Changed Files:
U   tools/gssmonger/trunk/gssmaster/ezlog_log4cpp.cpp
Modified: tools/gssmonger/trunk/gssmaster/ezlog_log4cpp.cpp
===================================================================
--- tools/gssmonger/trunk/gssmaster/ezlog_log4cpp.cpp	2009-02-26 20:32:35 UTC (rev 22057)
+++ tools/gssmonger/trunk/gssmaster/ezlog_log4cpp.cpp	2009-02-26 20:35:29 UTC (rev 22058)
@@ -145,7 +145,13 @@
   return Log4cPriority;
 }
                               
-Category *cat = NULL;
+struct CatStack {
+    Category *cat;
+    CatStack *parent;
+    CatStack(Category *c, CatStack *p = NULL) : cat(c), parent(p) { }
+};
+//Category *cat = NULL;
+static CatStack *cats = NULL;
 
 // Start a new log4cpp log
 EZLOGAPI ezStartBlock(IN OPTIONAL HANDLE OldLevel,
@@ -173,16 +179,17 @@
   char LogName[24];
   snprintf(LogName, 24, "gssMonger.%ld", BlockCounter);
   
-  cat = &Category::getInstance(LogName);
+  Category *cat = &Category::getInstance(LogName);
   cat->setAdditivity(true);
   cat->setAppender(app);
   cat->setAppender(appConsole);
+  cats = new CatStack(cat, cats);
 
   ezLogMsg(EZLOG_BLOCK, EZ_DEFAULT, "StartBlock %p from %p(%s)",
 	   (void *)cat,
 	   OldLevel,
 	   (OldLevel
-	    ? ((Category *)OldLevel)->getName().data()
+	    ? ((CatStack *)OldLevel)->cat->getName().data()
 	    : "?"));
 
   cat->log(etol_priority(LogLevel),
@@ -191,7 +198,7 @@
   BlockCounter++;
 
   if (NewLevel)
-      *NewLevel = (void*)cat;
+      *NewLevel = (void*)cats;
 
   return TRUE;
 }
@@ -216,24 +223,32 @@
 		    IN LPEZSTR LogString,
 		    IN va_list * ExtraArgs) {
 
-  if (cat == NULL) {
-    void* temp;
-    ezStartBlock( NULL, &temp, 0, LogLevel, "Autoinitializing log..." );
+  if (cats == NULL) {
+      void* temp;
+      ezStartBlock( NULL, &temp, 0, LogLevel, "Autoinitializing log..." );
   }
   
   char ProcessedLogString[4096];
   va_list * args = ExtraArgs;
 
-  snprintf(ProcessedLogString, sizeof(ProcessedLogString),
-	   "%s:%lu ", File, Line);
+  if (File) {
+      const char *basename;
+      basename = strchr(File, '/');
+      if (basename == NULL)
+	  basename = File;
+      else
+	  basename++;
+      snprintf(ProcessedLogString, sizeof(ProcessedLogString),
+	       "%s:%lu ", basename, Line);
+  } else
+      ProcessedLogString[0] = 0;
 
   vsnprintf(ProcessedLogString + strlen(ProcessedLogString),
 	    sizeof(ProcessedLogString) - strlen(ProcessedLogString),
 	    LogString, *args);
   va_end(*args);
 
-  cat->log(etol_priority(LogLevel),
-	   ProcessedLogString);
+  cats->cat->log(etol_priority(LogLevel), ProcessedLogString);
   
   return TRUE;
 }
@@ -253,14 +268,15 @@
 // Close the specified log4cpp log
 EZLOGAPI ezFinishBlock( IN OPTIONAL HANDLE handle ) {
     ezLogMsg(EZLOG_BLOCK, EZ_DEFAULT, "FinishBlock %p(%s)", handle,
-	     ((Category *)handle)->getName().data());
-  Category::shutdown();
-  cat = NULL;
+	     ((CatStack *)handle)->cat->getName().data());
+    CatStack *c2 = cats;
+    cats = c2->parent;
+    delete c2;
 }
 
 // Close the log4cpp log
 EZLOGAPI ezCloseLog( IN OPTIONAL ULONG flags, ... ) {
-  Category::shutdown();
+    Category::shutdown();
 }
 
 // Open the log4cpp log




More information about the cvs-krb5 mailing list