From 73fa1098cde2cdae8027ce163c08806b13cfdf93 Mon Sep 17 00:00:00 2001 From: scottmk Date: Mon, 27 Apr 2009 01:44:08 +0000 Subject: [PATCH 1/1] Performance tweak for osrfLog* functions: don't pass the message through VA_LIST_TO_STRING unless you're actually going to use it. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1694 9efc2488-bf62-4759-914b-345cdb29e865 --- src/libopensrf/log.c | 70 +++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 21 deletions(-) diff --git a/src/libopensrf/log.c b/src/libopensrf/log.c index 14fdf06..aca653e 100644 --- a/src/libopensrf/log.c +++ b/src/libopensrf/log.c @@ -20,11 +20,6 @@ static void _osrfLogDetail( int level, const char* filename, int line, char* msg static void _osrfLogToFile( const char* msg, ... ); static void _osrfLogSetXid( const char* xid ); -#define OSRF_LOG_GO(f,li,m,l) \ - if(!m) return; \ - VA_LIST_TO_STRING(m); \ - _osrfLogDetail( l, f, li, VA_BUF ); - void osrfLogCleanup( void ) { free(_osrfLogAppname); _osrfLogAppname = NULL; @@ -153,27 +148,60 @@ int osrfLogGetLevel( void ) { return _osrfLogLevel; } -void osrfLogError( const char* file, int line, const char* msg, ... ) - { OSRF_LOG_GO(file, line, msg, OSRF_LOG_ERROR); } -void osrfLogWarning( const char* file, int line, const char* msg, ... ) - { OSRF_LOG_GO(file, line, msg, OSRF_LOG_WARNING); } -void osrfLogInfo( const char* file, int line, const char* msg, ... ) - { OSRF_LOG_GO(file, line, msg, OSRF_LOG_INFO); } -void osrfLogDebug( const char* file, int line, const char* msg, ... ) - { OSRF_LOG_GO(file, line, msg, OSRF_LOG_DEBUG); } -void osrfLogInternal( const char* file, int line, const char* msg, ... ) - { OSRF_LOG_GO(file, line, msg, OSRF_LOG_INTERNAL); } -void osrfLogActivity( const char* file, int line, const char* msg, ... ) { - OSRF_LOG_GO(file, line, msg, OSRF_LOG_ACTIVITY); - _osrfLogDetail( OSRF_LOG_INFO, file, line, VA_BUF ); /* also log at info level */ +void osrfLogError( const char* file, int line, const char* msg, ... ) { + if( !msg ) return; + if( _osrfLogLevel < OSRF_LOG_ERROR ) return; + VA_LIST_TO_STRING( msg ); + _osrfLogDetail( OSRF_LOG_ERROR, file, line, VA_BUF ); +} + +void osrfLogWarning( const char* file, int line, const char* msg, ... ) { + if( !msg ) return; + if( _osrfLogLevel < OSRF_LOG_WARNING ) return; + VA_LIST_TO_STRING( msg ); + _osrfLogDetail( OSRF_LOG_WARNING, file, line, VA_BUF ); +} + +void osrfLogInfo( const char* file, int line, const char* msg, ... ) { + if( !msg ) return; + if( _osrfLogLevel < OSRF_LOG_INFO ) return; + VA_LIST_TO_STRING( msg ); + _osrfLogDetail( OSRF_LOG_INFO, file, line, VA_BUF ); +} + +void osrfLogDebug( const char* file, int line, const char* msg, ... ) { + if( !msg ) return; + if( _osrfLogLevel < OSRF_LOG_DEBUG ) return; + VA_LIST_TO_STRING( msg ); + _osrfLogDetail( OSRF_LOG_DEBUG, file, line, VA_BUF ); +} + +void osrfLogInternal( const char* file, int line, const char* msg, ... ) { + if( !msg ) return; + if( _osrfLogLevel < OSRF_LOG_INTERNAL ) return; + VA_LIST_TO_STRING( msg ); + _osrfLogDetail( OSRF_LOG_INTERNAL, file, line, VA_BUF ); +} + +void osrfLogActivity( const char* file, int line, const char* msg, ... ) { + if( !msg ) return; + if( _osrfLogLevel >= OSRF_LOG_INFO + || ( _osrfLogActivityEnabled && _osrfLogLevel >= OSRF_LOG_ACTIVITY ) ) + { + VA_LIST_TO_STRING( msg ); + + if( _osrfLogActivityEnabled && _osrfLogLevel >= OSRF_LOG_ACTIVITY ) + _osrfLogDetail( OSRF_LOG_ACTIVITY, file, line, VA_BUF ); + + /* also log at info level */ + if( _osrfLogLevel >= OSRF_LOG_INFO ) + _osrfLogDetail( OSRF_LOG_INFO, file, line, VA_BUF ); + } } /** Actually does the logging */ static void _osrfLogDetail( int level, const char* filename, int line, char* msg ) { - if( level == OSRF_LOG_ACTIVITY && ! _osrfLogActivityEnabled ) return; - if( level > _osrfLogLevel ) return; - if(!msg) return; if(!filename) filename = ""; char* label = "INFO"; /* level name */ -- 2.43.2