Boost logo

Boost :

From: Lars Gullik Bjønnes (larsbj_at_[hidden])
Date: 2002-04-09 17:58:56


"David A. Greene" <greened_at_[hidden]> writes:

| Eugene Karpachov wrote:
>> 9 Apr 2002 05:55:49 +0400 Ernie Makris wrote:
>>
>>> It would look like the following:
>>> log << log_debug << log_format("%e %1") % "config file not found";
>> ^^^^^^^
>> Please not that ugly format string again! Streams was invented to get
>> out of this cryptic, type-unsafe and processor-time-consuming feature,
>> so why not just to:
>> log << log_debug << log_errno() << " config file not found";
>
| I can't express my agreement with this enough. I'm sick of percent
| signs!
>
>>> The log stream would support levels, and a default level. etc...
>> IMHO log streambuf would be enough; the rest is trivial.
>
| For iostream logging, I agree. But the streambuf is non-trivial.
| :)As Gennadiy pointed out, more support may be desireable.

In LyX we have been using logging like this for a while:

/** DebugStream is a ostream intended for debug output.
    It has also support for a logfile. Debug output is output to cerr
    and if the logfile is set, to the logfile.

    Example of Usage:
    DebugStream debug;
    debug.level(Debug::INFO);
    debug.debug(Debug::WARN) << "WARN\n";
    debug[Debug::INFO] << "INFO\n";
    debug << "Always\n";

    Will output:
    INFO
    Always

    If you want to have debug output from time critical code you should
    use this construct:
    if (debug.debugging(Debug::INFO)) {
         debug << "...debug output...\n";
    }

    To give debug info even if no debug (NONE) is requested:
    debug << "... always output ...\n";

    To give debug output regardless of what debug level is set (!NONE):
    debug.debug() << "...on debug output...\n";
    debug[Debug::ANY] << "...on debug output...\n";

    To give debug output when a specific debug level is set (INFO):
    debug.debug(Debug::INFO) << "...info...\n";
    debug[Debug::INFO] << "...info...\n";

    To give debug output when either on of debug levels is set (INFO or CRIT):
    debug.debug(Debug::type(Debug::INFO | Debug::CRIT)) << "...info/crit...\n";
    debug[Debug::type(Debug::INFO | Debug::CRIT)] << "...info/crit...\n";

*/

It also has support for a log file, but that part has never really
been used.

It is easily extendable to syslog logging by creating a syslogbuf, I
guess other targets could be handled the same way.

In the implementation we use both a nullbuf, and a teebuf.

If someone wants the whole "lib" to look at send me a mail.

-- 
	Lgb

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