|
Boost : |
From: Daniel Frey (d.frey_at_[hidden])
Date: 2005-04-29 13:03:07
John Torjo wrote:
> I've just updated the Boost Log Library:
> http://torjo.com/code/logging-v132.zip
It's good to see progress on logging and what I've seen so far looks
promising. However...
> BOOST_LOG(app) << "testing " << i << '-' << j << '-' << k << std::endl;
> BOOST_LOG(dbg) << "this is a debug message, i=" << i << std::endl;
> BOOST_LOG(info) << "I just wanted to tell you something....";
...while I like the feeling of the stream approach from a user's
perspective, there is one (IMHO important) feature that can not be
implemented with it: Exception guards.
To illustrate my point, consider a "pure MACRO approach" like this:
std::string f()
{
throw 42;
}
BOOST_LOG( app, "Huhu!" + f() );
where BOOST_LOG is:
#define BOOST_LOG( logger, message ) \
do { if( logger.is_enabled() ) { \
try { logger.print( message ); } \
catch( const std::exception& e ) { \
logger.print( "Can't log \"" #message "\", e.what(): \"" + \
std::string( e.what() ) + "\"" ); \
} \
catch( ... ) { \
logger.print( "Can't log \"" #message "\", unknown exception" ); \
} \
} } while( false )
This feature helped us several times in the company when a log-message,
calling some complicated functions, failed in a production system. As
long as the above technique is applied, the log-file contains a good
hint for us what's wrong and the product is still running without the
customer noticing.
Regards, Daniel
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk