From 8d76b8066704be464c4988e47899f599bd3112a8 Mon Sep 17 00:00:00 2001 From: Thomas Ries Date: Fri, 14 May 2004 17:23:59 +0000 Subject: [PATCH] - INFO/WARN/ERROR are always logged to syslog, even if running in foreground (syslog still can be silenced using the silence_log config option) --- ChangeLog | 3 +++ src/log.c | 40 +++++++++++++++++++++++++++++----------- src/log.h | 2 +- src/siproxd.c | 4 +++- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 488b1c9..ad0b1b7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 0.5.6 ===== + 14-May-2004: - INFO/WARN/ERROR are always logged to syslog, even + if running in foreground (syslog still can be silenced + using the silence_log config option) 09-May-2004: - Authentication headers: enquote Realm (linphone) - complain about empty values in config file - fli4l-uclibc: statically link against libpthread diff --git a/src/log.c b/src/log.c index a0989be..9241fc8 100644 --- a/src/log.c +++ b/src/log.c @@ -32,7 +32,7 @@ static char const ident[]="$Id$"; -static int log_to_syslog=0; +static int log_to_stdout=0; static int debug_pattern=0; /* * What shall I log to syslog? @@ -59,8 +59,8 @@ int log_get_pattern(void) { return debug_pattern; } -void log_set_tosyslog(int tosyslog) { - log_to_syslog=tosyslog; +void log_set_stdout(int tostdout) { + log_to_stdout=tostdout; } void log_set_silence(int level) { @@ -86,7 +86,10 @@ void log_debug(int class, char *file, int line, const char *format, ...) { va_start(ap, format); pthread_mutex_lock(&log_mutex); - if (! log_to_syslog) { + /* + * DEBUG output is either STDOUT or SYSLOG, but not both + */ + if (log_to_stdout) { /* not running as daemon - log to STDERR */ time(&t); tim=localtime(&t); @@ -117,7 +120,11 @@ void log_error(char *file, int line, const char *format, ...) { va_start(ap, format); pthread_mutex_lock(&log_mutex); - if (! log_to_syslog) { + /* + * INFO, WARN, ERROR output is always to syslog and if not daemonized + * st STDOUT as well. + */ + if (log_to_stdout) { /* not running as daemon - log to STDERR */ time(&t); tim=localtime(&t); @@ -126,7 +133,8 @@ void log_error(char *file, int line, const char *format, ...) { vfprintf(stderr, format, ap); fprintf(stderr,"\n"); fflush(stderr); - } else if (silence_level < 4) { + } + if (silence_level < 4) { /* running as daemon - log via SYSLOG facility */ vsnprintf(string, sizeof(string), format, ap); syslog(LOG_USER|LOG_WARNING, "%s:%i ERROR:%s", file, line, string); @@ -148,7 +156,11 @@ void log_warn(char *file, int line, const char *format, ...) { va_start(ap, format); pthread_mutex_lock(&log_mutex); - if (! log_to_syslog) { + /* + * INFO, WARN, ERROR output is always to syslog and if not daemonized + * st STDOUT as well. + */ + if (log_to_stdout) { /* not running as daemon - log to STDERR */ time(&t); tim=localtime(&t); @@ -157,7 +169,8 @@ void log_warn(char *file, int line, const char *format, ...) { vfprintf(stderr, format, ap); fprintf(stderr,"\n"); fflush(stderr); - } else if (silence_level < 3) { + } + if (silence_level < 3) { /* running as daemon - log via SYSLOG facility */ vsnprintf(string, sizeof(string), format, ap); syslog(LOG_USER|LOG_NOTICE, "%s:%i WARNING:%s", file, line, string); @@ -179,7 +192,11 @@ void log_info(char *file, int line, const char *format, ...) { va_start(ap, format); pthread_mutex_lock(&log_mutex); - if (! log_to_syslog) { + /* + * INFO, WARN, ERROR output is always to syslog and if not daemonized + * st STDOUT as well. + */ + if (log_to_stdout) { /* not running as daemon - log to STDERR */ time(&t); tim=localtime(&t); @@ -188,7 +205,8 @@ void log_info(char *file, int line, const char *format, ...) { vfprintf(stderr, format, ap); fprintf(stderr,"\n"); fflush(stderr); - } else if (silence_level < 2) { + } + if (silence_level < 2) { /* running as daemon - log via SYSLOG facility */ vsnprintf(string, sizeof(string), format, ap); syslog(LOG_USER|LOG_NOTICE, "%s:%i INFO:%s", file, line, string); @@ -207,7 +225,7 @@ void log_dump_buffer(int class, char *file, int line, char tmp[8], tmplin1[80], tmplin2[80]; if ((debug_pattern & class) == 0) return; - if (log_to_syslog) return; + if (!log_to_stdout) return; pthread_mutex_lock(&log_mutex); fprintf(stderr,"---BUFFER DUMP follows---\n"); diff --git a/src/log.h b/src/log.h index 0ae9d42..391f2f4 100644 --- a/src/log.h +++ b/src/log.h @@ -38,7 +38,7 @@ void log_set_pattern(int pattern); int log_get_pattern(void); -void log_set_tosyslog(int tosyslog); +void log_set_stdout(int tostdout); void log_set_silence(int level); #undef DEBUG diff --git a/src/siproxd.c b/src/siproxd.c index f86f40a..caa8bf9 100644 --- a/src/siproxd.c +++ b/src/siproxd.c @@ -85,6 +85,8 @@ int main (int argc, char *argv[]) struct sigaction act; + log_set_stdout(1); + /* * setup signal handlers */ @@ -181,7 +183,7 @@ int main (int argc, char *argv[]) setsid(); if (fork()!=0) exit(0); - log_set_tosyslog(1); + log_set_stdout(0); INFO("daemonized, pid=%i", getpid()); }