|
Boost : |
From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2004-03-19 06:13:47
John Torjo wrote:
> Daniel Frey wrote:
>
>> John Torjo wrote:
>>> if (activity_log()) activity_log() << ...;
>>
>> Hm, too verbose for my taste. With the macro, you get it for free.
>>
> True. I can also add a macro, something like:
>
> log(activity) << ...;
OK, although there is more to keep in mind. In our logging system, we
also added a try/catch macro around the expression that is to be logged.
The reason is, that we never want a log-message to abort the program. I
attached our actual implementation ('attached' to prevent reformatting),
obviously I can't show the complete system :)
Regards, Daniel
-- Daniel Frey aixigo AG - financial solutions & technology Schloß-Rahe-Straße 15, 52072 Aachen, Germany fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99 eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de
/// The basic underlying LOG-macro (implementing the guard if requested)
#ifdef AIXIGO_NO_LOG_GUARD
#define AIXIGO_LOG( level, errorLevel, message ) \
do { \
if( ::Base::Log::hasLoggers( level ) ) { \
::Base::Log::log( level, __FILE__, __LINE__, message ); \
} \
} while( false )
#else
#define AIXIGO_LOG( level, errorLevel, message ) \
do { \
try { \
if( ::Base::Log::hasLoggers( level ) ) { \
::Base::Log::log( level, __FILE__, __LINE__, message ); \
} \
} catch( ... ) { \
::Base::Log::log( errorLevel, __FILE__, __LINE__, \
"Failed to process " #level " log message \"" #message "\"" ); \
} \
} while( false )
#endif
#define LOG_TRACE( message ) AIXIGO_LOG( ::Base::Log::TRACE, ::Base::Log::ERROR, message )
#define LOG_DEBUG( message ) AIXIGO_LOG( ::Base::Log::DEBUG, ::Base::Log::ERROR, message )
#define LOG_INFO( message ) AIXIGO_LOG( ::Base::Log::INFO, ::Base::Log::ERROR, message )
#define LOG_WARN( message ) AIXIGO_LOG( ::Base::Log::WARN, ::Base::Log::ERROR, message )
#define LOG_ERROR( message ) AIXIGO_LOG( ::Base::Log::ERROR, ::Base::Log::ERROR, message )
#define LOG_FATAL( message ) AIXIGO_LOG( ::Base::Log::FATAL, ::Base::Log::FATAL, message )
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk