
I think it's the wrong approach. In our company we have implemented logging through macros which has one very important property: When I write
LOG_DEBUG( whatever() );
into my source, then whatever() is only evaluated when the debug-logger is active. The macro basically expands to something like this:
if( Base::hasLogger( LogLevel::DEBUG ) ) Base::log( whatever(), LogLevel::DEBUG );
I think this cannot be done without macros as normal function calls (including operator<< for streams) need to evaluate their arguments before they are called. As the difference in the application execution speed can vary by a factor of 1000, this is a very valuable optimization for us. My 2ยข.
Man, you must be doing a LOT of logging ;) I do quite a lot of logging myself, but I've never needed anything like above. Anyway, in my code I have functions, which return a log_stream (a thread-safe wrapper over a stream). And use it like this: activity_log() << "My app. started at" << time(0) << std::endl; error_log() << "should have not arrived here" << std::endl; // etc. And if I truly want, I can implement an operator bool(), and be able to disable it at runtime, like this: if (activity_log()) activity_log() << ...; Best, John