Boost logo

Boost :

From: Richard Day (richardvday_at_[hidden])
Date: 2007-04-05 10:43:13


Michael Lacher wrote:
> Maybe optional log information (channel, type, loglevel, ...) could all
> be passed similar to manipulators in std::stream. This would keep the
> basic interface clean (just << operator) and extensible. There would be
> no need to anticipate numbers/types of function arguments.
>
> If people prefer a functional interface, then they could go for either
>
> #define MYLOG1(LEVEL,CHANNEL,MESSAGE) logger << setLevel(LEVEL) <<
> setChannel(CHANNEL) << MESSAGE << endl
>
>
> MYLOG1(WARNING,"Debug","Caught Exception: " << e.what());
>
> or
>
> #define MYLOG2(LEVEL,CHANNEL) logger << setLevel(LEVEL) <<
> setChannel(CHANNEL)
>
>
> MYLOG2(WARNING,"Debug") << "Caught Exception: " << e.what() << endl;
>
> Of course a commonly used subset of such macros could be provided.
>
> Michael
>
>
My thinking is that macros are really just for trace during debugging
for the most part.
Basically so you have a way to turn them off in a release build if/when
desired.
Stream statements are much nicer for regular logging. No need to know
arguments ahead of time and setup macros for every possibility.

Level/Class/Channel etc can be set easily using manipulators.
Naturally we need functions for setting things like that as well as
turning sinks off and on again etc.
Best to have manipulators for these as well so you can do it directly in
the stream statement if/when desired as well.

I would rather write a single stream statement then write
logger << "Something here";
logger.turnoffwhatever()
logger << "rest of the statement";
logger.turnitonagain();

logger << "Something here" << turnoffwhatever << "rest of the statement"
<< turnonagain;

Just my 2 cents.

Richard Day


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