Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-04-16 00:57:33

John Torjo wrote:

> True. I looked at log4j (for the nth time ;)) I don't like it. It's way
> too complex.
> There's no need for Filter, Layout and a lot of other classes (IMHO).
> What I want is to create a simple correspondence from a log_id (a level)
> into a log function.
> Having that, you can always say something like:
> LOG(activity) << whatever... << std::endl;
> if 'activity' is turned off this nothing gets evaluated (yes, LOG is a
> macro ;))
> If it's turned on, the whole message is composed and the function
> corresponding to 'activity' level is called.

That's OK.

>>1. User gets hold of boost::logger and outputs something
>>2. logger emits signal which can be then connected to a number of consumer
>>3. First consumer might be 'filter' which determines if the message should
>>be output at all. If it should be output, it emits signal again, which
>>might be delivered further
>>4. 'filter' might be connected to 'formatter', which adds timestamp and
>>again emits the signal.
>>5. 'formatter' might be connected to 'stream_writer' which stores the
>>message to a file and does nothing more.
> I think the above is too complicated.

Is it? The basic idea is
(1) to have functional object to do the logging
(2) allow to form chain of responsibility pattern from individual objects to
make the system for flexible.

> Here's how I see it:
> 1. Given a log level, the user gets hold of the corresponding
> boost::logger and tries to output something.

I think that hierarchical loggers ala log4j are necessary.

> 2a. If that log is disabled, nothing else happens.
> 2b. If that log is enabled, the message to be outputted is written to a
> stringstream, then
> converted to a string..
> The function corresponding to its level is called. That's it!

What I propose is that this function can forward the request (after some
processing) to other functions. In other words, you focus on front-end
interface while I talk about inner workings.

> If you want formatter (your step 5.) or prefix (your step 4.), you can
> simply do them in your custom function.

It simpler (IMO) to write

    syslog_appender sl;
    file_appender fl;
    timestamp_adder t;

that to write a custom function do to the same. Further, with a custom
function you cannot customize the processing chain from config file.

Besides, I think configuring loggers from config file is a very good thing,

- Volodya

Boost list run by bdawes at, gregod at, cpdaniel at, john at