From: miker Date: Tue, 26 Jun 2007 03:04:37 +0000 (+0000) Subject: Patch from Scott McKellar, finishing off the "log to stderr when all esle fails"... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=229fadfb7911191f84ed79256d6feec40048cff2;p=opensrf%2Fbjwebb.git 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 --- 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 ); }