Boost logo

Boost :

Subject: Re: [boost] [log] Review-ready version in the Vault
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2009-02-11 14:28:31

vicente.botet wrote:
>> I have some innocent questions:
>> * Is logging thread-safe?
>> * If yes, are the lines interleaved as it is the case for output streams?
>> * If not could you point out how and where in the implementation this is handled?
> Hi again,
> well i have found some anwers to my questions on the document. I'll come back later on.

I'm glad you did. :)

> How a log record is recognized, i.e. I don't see std::endl neither std::flush are used in the examples. How many lines result in the following example if condifiton is true (2 or 3)
> src::logger_mt& lg = my_logger::get();
> if (lg.open_record()) {
> lg.strm() << "Hello ";
> lg.strm() << "world!";
> }

That one is not valid in the current implementation. It should be
replaced with:

   if (lg.open_record())
     lg.strm() << "Hello ";
   if (lg.open_record())
     lg.strm() << "world!";

This is because strm() returns a temporary object that confirms the
opened log record on its destruction. Once confirmed, the record is
dispatched and cannot be modified, so a new record must be opened.

> // do something
> if (condition) {
> if (lg.open_record()) lg.strm() << "Bye!";
> }

Every complete streaming statement is a log record. So, you emit three
records in your code sample, assuming that all conditions are true and
the needed corrections are made.

> Can other logs be interleaved between "Hello " , "world!" and Bye in a multi threaded program?


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