From 5f31ffa559c431c9ec9b983e121ca7a3c7b0775f Mon Sep 17 00:00:00 2001 From: Steven Dake Date: Tue, 1 Jul 2008 22:08:15 +0000 Subject: [PATCH] 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 --- exec/logsys.c | 12 ++++++++---- exec/logsys.h | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/exec/logsys.c b/exec/logsys.c index d6264000..eee135b5 100644 --- a/exec/logsys.c +++ b/exec/logsys.c @@ -69,8 +69,6 @@ static FILE *logsys_file_fp = NULL; 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 @@ static void logsys_buffer_flush (void); 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 @@ static void _log_printf ( 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 @@ static void _log_printf ( } 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); diff --git a/exec/logsys.h b/exec/logsys.h index c88267a6..a451bbad 100644 --- a/exec/logsys.h +++ b/exec/logsys.h @@ -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.