Opened 6 years ago

Closed 6 years ago

#12178 closed Patches (fixed)

Log record stream state persists between log statements

Reported by: oe@… Owned by: Andrey Semashev
Milestone: To Be Determined Component: log
Version: Boost 1.60.0 Severity: Problem
Keywords: log, stream, state Cc:

Description

Hello,

the issue is best illustrated with the following example:

#include <ios>
#include <boost/log/trivial.hpp>

int
main()
   {
   BOOST_LOG_TRIVIAL(trace) << "dec: " << 16;
   BOOST_LOG_TRIVIAL(trace) << "hex: " << std::hex << 16;
   BOOST_LOG_TRIVIAL(trace) << "dec: " << 16;
   }

which prints something like:

... [trace]   dec: 16
... [trace]   hex: 10
... [trace]   dec: 10

Obviously, the state of the log stream persists between the individual log statements. To me this was quite surprising, as the documentation and also the code itself conveys the notion of independent log records being created and processed; attributes for example use the same manipulator syntax (add_value()/add_value_manip<>), but then only apply to the current log record under construction. And if log records are created manually via open_record() asf., one also creates a new log stream for each record.

The reason for the observed behaviour is that log streams are pooled by the implementation, and thus the same instance gets used in all three log statements in the example above. To alleviate the effects of this implementation detail(?), I'd suggest that (a common subset of) the stream state is reset to its default values when a stream is retrieved from the pool to be handed out to a log statement. Does this sound reasonable? I've prepared a patch along these lines that at least in my case solves the problem (see attachment)...

Thanks and regards
Oliver Ebert

Attachments (1)

reset_stream_state.patch (1.8 KB ) - added by oe@… 6 years ago.

Download all attachments as: .zip

Change History (2)

by oe@…, 6 years ago

Attachment: reset_stream_state.patch added

comment:1 by Andrey Semashev, 6 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.