On Fri, 2008-06-27 at 15:33 -0400, Lon Hohberger wrote:
> If you add LOG_MODE_SHORT_FILELINE, it changes the the following debug
> line from:
> 
> [/sandbox/lhh/cluster/fence/agents/xvm/fence_xvmd.c:0587] My Node ID = 1
> 
> ...to:
> 
> [fence_xvmd.c:0587] My Node ID = 1
> 
> Most developers who insert LOG_DEBUG lines will be able to determine out
> of context which source code file a particular log message came from, so
> it is arguable the entire path spec is unnecessary (and perhaps
> "SHORT_FILELINE" should be the default; but we'll leave that for another
> day).

This patch supplants the previous one and adds support for setting
"nosubsys" as a mode flag instead of its own global variable (which
can't currently be unset).

-- Lon
Index: logsys.c
===================================================================
--- logsys.c	(revision 1568)
+++ logsys.c	(working copy)
@@ -69,8 +69,6 @@
 
 static int logsys_facility = LOG_DAEMON;
 
-static int logsys_nosubsys = 0;
-
 static int logsys_wthread_active = 0;
 
 static pthread_mutex_t logsys_config_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -121,7 +119,7 @@
 
 void _logsys_nosubsys_set (void)
 {
-	logsys_nosubsys = 1;
+	logsys_mode |= LOG_MODE_NOSUBSYS;
 }
 
 int logsys_facility_id_get (const char *name)
@@ -298,6 +296,7 @@
 	char newstring[4096];
 	char log_string[4096];
 	char char_time[512];
+	char *p = NULL;
 	struct timeval tv;
 	int i = 0;
 	int len;
@@ -331,9 +330,14 @@
 	}
 
 	if ((priority == LOG_LEVEL_DEBUG) || (logsys_mode & LOG_MODE_DISPLAY_FILELINE)) {
+		if (logsys_mode & LOG_MODE_SHORT_FILELINE) {
+			p = strrchr(file, '/');
+			if (p) 
+				file = ++p;
+		}
 		sprintf (&newstring[i], "[%s:%04u] %s", file, line, format);
 	} else {	
-		if (logsys_nosubsys == 1) {
+		if (logsys_mode & LOG_MODE_NOSUBSYS) {
 			sprintf (&newstring[i], "%s", format);
 		} else {
 			sprintf (&newstring[i], "[%-5s] %s", logsys_loggers[id].subsys, format);
Index: logsys.h
===================================================================
--- logsys.h	(revision 1568)
+++ logsys.h	(working copy)
@@ -52,6 +52,8 @@
 #define LOG_MODE_DISPLAY_TIMESTAMP	(1<<7)
 #define LOG_MODE_BUFFER_BEFORE_CONFIG	(1<<8)
 #define LOG_MODE_FLUSH_AFTER_CONFIG	(1<<9)
+#define LOG_MODE_SHORT_FILELINE		(1<<10)
+#define LOG_MODE_NOSUBSYS		(1<<11)
 
 /*
  * Log priorities, compliant with syslog and SA Forum Log spec.
_______________________________________________
Openais mailing list
Openais@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to