Boost C++ Libraries: Ticket #12178: Log record stream state persists between log statements https://svn.boost.org/trac10/ticket/12178 <p> Hello, </p> <p> the issue is best illustrated with the following example: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;ios&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/log/trivial.hpp&gt;</span><span class="cp"></span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="n">BOOST_LOG_TRIVIAL</span><span class="p">(</span><span class="n">trace</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;dec: &quot;</span> <span class="o">&lt;&lt;</span> <span class="mi">16</span><span class="p">;</span> <span class="n">BOOST_LOG_TRIVIAL</span><span class="p">(</span><span class="n">trace</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;hex: &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">hex</span> <span class="o">&lt;&lt;</span> <span class="mi">16</span><span class="p">;</span> <span class="n">BOOST_LOG_TRIVIAL</span><span class="p">(</span><span class="n">trace</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;dec: &quot;</span> <span class="o">&lt;&lt;</span> <span class="mi">16</span><span class="p">;</span> <span class="p">}</span> </pre></div></div><p> which prints something like: </p> <pre class="wiki">... [trace] dec: 16 ... [trace] hex: 10 ... [trace] dec: 10 </pre><p> 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&lt;&gt;), 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. </p> <p> 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)... </p> <p> Thanks and regards<br /> Oliver Ebert </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12178 Trac 1.4.3 oe@… Thu, 05 May 2016 14:27:08 GMT attachment set https://svn.boost.org/trac10/ticket/12178 https://svn.boost.org/trac10/ticket/12178 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">reset_stream_state.patch</span> </li> </ul> Ticket Andrey Semashev Sun, 17 Jul 2016 13:32:36 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/12178#comment:1 https://svn.boost.org/trac10/ticket/12178#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fixed in <a class="ext-link" href="https://github.com/boostorg/log/commit/f15e9d413c9faf582ab4e0dcc827d521e865d1bc"><span class="icon">​</span>https://github.com/boostorg/log/commit/f15e9d413c9faf582ab4e0dcc827d521e865d1bc</a>. Thanks. </p> Ticket