Boost logo

Boost :

From: John Eddy (johneddy_at_[hidden])
Date: 2005-01-28 15:28:31


Thank you for pointing me to that. My implementation is quite different
but I like many features of the Torjo library. Some of the major
differences between the Torjo library and mine include:

 From what I can see in the Torjo library:
There is no fixed collection of logging levels. You declare separate
logs and log to the one that is applicable.
A global function returning a reference to a log is created in order to
share a log as done in the detail.h file of the examples.
He has designed his logs to accept logging text using an ostringstream.
He supports use of "appenders" to echo messages.

My library:
Has a fixed collection of logging levels and so a single log can be used
and the desired level specified.
A log is declared at any scope you wish and can be shared in the same
manner as any other object (I most often pass one around by reference).
My logs accept messages as strings.
My library does not currently support the "appenders" as his does. I
will add this, I like it very much. It is a must.

My library is set up to log entries conditionally based on the currently
applicable logging level and the level at which the entry request was
made. The logging levels are FATAL > SHOUT > ERROR > WARN > INFO >
DEBUG > DETAIL. I modeled the logging levels after those of the COUGAAR
agent architecture logging facility.

Take a look at the simple example below.

#include <boost/logger.hpp>
#include <iterator>
#include <iostream>

using namespace std;
using namespace boost::logging;

struct test1 { int field; };

int main(int argc, char* argv[])
{
    logger mylog; // default level is WARN

    // anything logged at this point would only cause an entry creation
    // if it were logged a the WARN level or greater.
    mylog.warn("This is an anonomous log entry");
    mylog.warn("main", "main is logging a warning");

    // create some items to associate with log entries.
    test1 t11, t12;

    // make the logging level for all not-otherwise-level-set test1
objects DEBUG
    mylog.set_logging_level<test1>(logger::DEBUG);

    // now, the first statement below will cause a log entry and the
second will not.
    mylog.info(&t11, "This is an info entry");
    mylog.detail(&t12, "This is a detail entry");

    // now make the logging level for t11 FATAL
    mylog.set_logging_level(&t11, logger::FATAL);

    // now, the first statement below will cause a log entry and the
second will not.
    mylog.fatal(&t11, "Call me T11", "This is the fatal error text");
    mylog.debug(&t11, "This is a T11 debug message");

    // logging messages can then be retrieved from the log using
predicates, of which
    // a number of simple examples I've already created. For now, I
will just write
    // all logged messages to the screen.
    const log_entry_list& all = mylog.get_all_entries();
    copy(all.begin(), all.end(),
ostream_iterator<logger::log_entry>(cerr, ""));
}

The above program causes the output:
2005-Jan-28 14:58:33.903660: Anonymous, WARN - This is an anonomous log
entry
2005-Jan-28 14:58:33.903660: main, WARN - main is logging a warning
2005-Jan-28 14:58:33.923689: struct test1, INFO - This is an info entry
2005-Jan-28 14:58:33.923689: Call me T11, FATAL - This is the fatal
error text

John

Jonathan Turkanis wrote:

>John Eddy wrote:
>
>
>>Would anyone be interested in a library for doing logging?
>>
>>
>
>Yes.
>
>
>
>>I've written one for my own purposes and thought others might find it
>>useful. It will store log entries at various levels (FATAL, SHOUT,
>>ERROR, WARN, INFO, DEBUG, DETAIL). There is a default level and the
>>level can be customized for entries by individual instances of any
>>type and for entries by any types as a whole.
>>
>>
>
>
>
>>I'll be glad to provide more information if anyone is interested.
>>
>>
>
>You might want to describe briefly how your library compares to existing
>libraries, e.g., to this one by John Torjo
>
>http://lists.boost.org/MailArchives/boost/msg73854.php
>
>which he may eventually propose for review.
>
>
>
>>John
>>
>>
>
>
>
>_______________________________________________
>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