Bläddra i källkod

Add two new modes LOG_MODE_SHORT_FILELINE and LOG_MODE_NOSUBSYS.
LOG_MODE_SHORT_FILELINE strips the leading path from the file name in
a debug output. LOG_MODE_NOSUBSYS removes a global variable and provides
the ability to set or unset this via config_mode_set.


git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1570 fd59a12c-fef9-0310-b244-a6a79926bd2f

Steven Dake 17 år sedan
förälder
incheckning
5f31ffa559
2 ändrade filer med 10 tillägg och 4 borttagningar
  1. 8 4
      exec/logsys.c
  2. 2 0
      exec/logsys.h

+ 8 - 4
exec/logsys.c

@@ -69,8 +69,6 @@ static FILE *logsys_file_fp = NULL;
 
 
 static int logsys_facility = LOG_DAEMON;
 static int logsys_facility = LOG_DAEMON;
 
 
-static int logsys_nosubsys = 0;
-
 static int logsys_wthread_active = 0;
 static int logsys_wthread_active = 0;
 
 
 static pthread_mutex_t logsys_config_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t logsys_config_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -121,7 +119,7 @@ static void logsys_buffer_flush (void);
 
 
 void _logsys_nosubsys_set (void)
 void _logsys_nosubsys_set (void)
 {
 {
-	logsys_nosubsys = 1;
+	logsys_mode |= LOG_MODE_NOSUBSYS;
 }
 }
 
 
 int logsys_facility_id_get (const char *name)
 int logsys_facility_id_get (const char *name)
@@ -298,6 +296,7 @@ static void _log_printf (
 	char newstring[4096];
 	char newstring[4096];
 	char log_string[4096];
 	char log_string[4096];
 	char char_time[512];
 	char char_time[512];
+	char *p = NULL;
 	struct timeval tv;
 	struct timeval tv;
 	int i = 0;
 	int i = 0;
 	int len;
 	int len;
@@ -331,9 +330,14 @@ static void _log_printf (
 	}
 	}
 
 
 	if ((priority == LOG_LEVEL_DEBUG) || (logsys_mode & LOG_MODE_DISPLAY_FILELINE)) {
 	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);
 		sprintf (&newstring[i], "[%s:%04u] %s", file, line, format);
 	} else {	
 	} else {	
-		if (logsys_nosubsys == 1) {
+		if (logsys_mode & LOG_MODE_NOSUBSYS) {
 			sprintf (&newstring[i], "%s", format);
 			sprintf (&newstring[i], "%s", format);
 		} else {
 		} else {
 			sprintf (&newstring[i], "[%-5s] %s", logsys_loggers[id].subsys, format);
 			sprintf (&newstring[i], "[%-5s] %s", logsys_loggers[id].subsys, format);

+ 2 - 0
exec/logsys.h

@@ -52,6 +52,8 @@
 #define LOG_MODE_DISPLAY_TIMESTAMP	(1<<7)
 #define LOG_MODE_DISPLAY_TIMESTAMP	(1<<7)
 #define LOG_MODE_BUFFER_BEFORE_CONFIG	(1<<8)
 #define LOG_MODE_BUFFER_BEFORE_CONFIG	(1<<8)
 #define LOG_MODE_FLUSH_AFTER_CONFIG	(1<<9)
 #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.
  * Log priorities, compliant with syslog and SA Forum Log spec.