Boost logo

Boost :

From: Stuart Dootson (stuart.dootson_at_[hidden])
Date: 2005-08-07 03:45:24


On 8/5/05, John Torjo <john.lists_at_[hidden]> wrote:

<snip>

> >
> > 2. Is it possible to query for the current logging level? If logging
> > activities take a significant amount of time, but they won't be
> > output, you don't want to do them. As an example - I've written
>
> For Boost.Log, if a message should not be outputted, logging activities
> won't take place.
>
> It's something like this:
> // pseudocode
> if ( !should_write_msg(log,some_level) ; else log.stream()
>
> So when you write:
>
> BOOST_LOGL(lg,err) << "this " << "is an error" << std::endl;
>
> is equivalent to:
>
> if ( !should_write_msg(lg,err)) ;
> else lg.stream() << "this " << "is an error" << std::endl;
>
> > libraries to decode debug information (Dwarf, Stabs etc). These would
> > at a high logging level, construct and output a textual equivalent of
> > a debug record (which took significant time). The text construction
> > wouldn't be done unless log output was going to be done.
> >
>
> Is this what you wanted?
>
> Best,
> John
>

John - you should have told me to RTFM! I've found exactly what I
wanted on the 'Efficiency' page. This is the sort of thing I want to
do:

if (<some-log>()(boost::logging::level::my_error))
{
   std::ostringstream oss;
   // v is a vector<int>
   std::copy(v.begin(), v.end(), std::ostream_iterator<int>(oss, ", "));
   BOOST_LOGL(<some-log>, my_error) << oss.str() << "\n";
}

Now, that example can be modified to write to the logging stream
directly using this:

std::copy(v.begin(), v.end(),
std::ostream_iterator<int>(*<some-log>().stream().stream(), ", "));
BOOST_LOGL(<some-log>, my_error) << "\n";

First question - is this usage that you envisaged? . Secondly, the output is

09:30:35 [app] 0, 1, 2, 3, 09:30:35 [app]

rather than

09:30:35 [app] 0, 1, 2, 3,

because of the second log statement prepending the time before the
"\n". Is there any way of getting the required output using the above
code pattern, by somehow stopping the log modifiers?

Stuart Dootson


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