From 229fadfb7911191f84ed79256d6feec40048cff2 Mon Sep 17 00:00:00 2001 From: miker Date: Tue, 26 Jun 2007 03:04:37 +0000 Subject: [PATCH] Patch from Scott McKellar, finishing off the "log to stderr when all esle fails" work: Currently if we have asked to log to a file, but we haven't yet specified the name of that log file, then any messages issued are dropped. With this patch, any messages issued under these conditions will be rerouted to standard error. The rerouting is only temporary, applying only to the current message. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@977 9efc2488-bf62-4759-914b-345cdb29e865 --- src/libopensrf/log.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/libopensrf/log.c b/src/libopensrf/log.c index 92023ae..10f2d30 100644 --- a/src/libopensrf/log.c +++ b/src/libopensrf/log.c @@ -195,7 +195,14 @@ static void _osrfLogDetail( int level, const char* filename, int line, char* msg char* xid = (_osrfLogXid) ? _osrfLogXid : ""; - if(_osrfLogType == OSRF_LOG_TYPE_SYSLOG ) { + int logtype = _osrfLogType; + if( logtype == OSRF_LOG_TYPE_FILE && !_osrfLogFile ) + { + // No log file defined? Temporarily reroute to stderr + logtype = OSRF_LOG_TYPE_STDERR; + } + + if( logtype == OSRF_LOG_TYPE_SYSLOG ) { char buf[1536]; memset(buf, 0x0, 1536); /* give syslog some breathing room, and be cute about it */ @@ -207,10 +214,10 @@ static void _osrfLogDetail( int level, const char* filename, int line, char* msg syslog( fac | lvl, "[%s:%ld:%s:%d:%s] %s", label, (long) getpid(), filename, line, xid, buf ); } - else if( _osrfLogType == OSRF_LOG_TYPE_FILE ) + else if( logtype == OSRF_LOG_TYPE_FILE ) _osrfLogToFile( "[%s:%ld:%s:%d:%s] %s", label, (long) getpid(), filename, line, xid, msg ); - else if( _osrfLogType == OSRF_LOG_TYPE_STDERR ) + else if( logtype == OSRF_LOG_TYPE_STDERR ) fprintf( stderr, "[%s:%ld:%s:%d:%s] %s\n", label, (long) getpid(), filename, line, xid, msg ); } -- 2.43.2