
19 Mar
2004
19 Mar
'04
3:19 a.m.
Darren Cook wrote:
The problem comes when I have a function that takes an ostream; then I have to expose the internals:
LOG("Here is data:");LOG(obj->debug_info(*logfile,true,false));
Is there a better way?
Yes, #define SOME_LOG_MACRO( MiscParams) \ if ( ! ShouldLog( MiscParams) ) \ { /* Don't execute, or log anything */ \ } \ else /* create something that returns an ostream& derived instance */ (MiscParams).GetStream () You can then use: SOME_LOG_MACRO( xxx) << "foo:" << foo << " bar:" << bar; and it will only execute the << methods if logging is enabled, or if it's necessary based on whatever you define. Plus, the streamed data doesn't have to be included in the macro as a parameter. Cheers...