Boost logo

Boost :

From: Darren Cook (darren_at_[hidden])
Date: 2004-03-19 20:11:15


Thanks for the reply. I think your solution solves different problems
(conditional inclusion; not including streamed data as macro parameter).

Having read other messages in this thread I think I should pass a 2nd param
to the LOG macro: an identifier that returns the ostream to use. But next
time I need logging I'll probably try one of the log4J projects mentioned.

Darren

>> 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...
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk