title: How do you disable auto-flush for Boost Log
body: <p>I am using <a href="https://www.boost.org/doc/libs/1_71_0/libs/log/doc/html/index.html" rel="nofollow noreferrer">Boost.Log</a> to log various sets of data to different files. I would like to have the <code>auto_flush</code> feature enabled for some files, but disabled for others (so that a newline is not inserted on each consecutive log statement). I couldn't get this to work in my larger project. So I simplified the problem down to just one file, but it appears that <code>auto_flush</code> is still cannot be disabled. Here is code for a minimal example:</p>
  
  <p><strong>test.hpp</strong>:</p>
  
  <pre><code>#include &lt;fstream&gt;
  #include &lt;boost/shared_ptr.hpp&gt;
  #include &lt;boost/smart_ptr/make_shared_object.hpp&gt;
  #include &lt;boost/log/core.hpp&gt;
  #include &lt;boost/log/sinks/sync_frontend.hpp&gt;
  #include &lt;boost/log/sinks/text_ostream_backend.hpp&gt;
  #include &lt;boost/log/trivial.hpp&gt;
  
  void init();
  </code></pre>
  
  <p><strong>test.cpp</strong>:</p>
  
  <pre><code>#include "test.hpp"
  
  void init() {
      // Initialize sink.
      typedef boost::log::sinks::synchronous_sink&lt;boost::log::sinks::text_ostream_backend&gt; text_sink;
      // Grab the Boost Log core.
      auto coreHandle = boost::log::core::get();
      // Add stream 1.
      boost::shared_ptr&lt;text_sink&gt; sink = boost::make_shared&lt;text_sink&gt;();
      sink-&gt;locked_backend()-&gt;add_stream(
              boost::make_shared&lt;std::ofstream&gt;("category1.log"));
      sink-&gt;locked_backend()-&gt;auto_flush(false);
      coreHandle-&gt;add_sink(sink);
  }
  </code></pre>
  
  <p><strong>main.cpp</strong>:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include "test.hpp"
  
  // Main entry point to program.
  int main(int numArg, char const * const arguments[]) {
  
      double number1 = 42;
  
      init();
  
      BOOST_LOG_TRIVIAL(info) &lt;&lt; "This message should go to category 1 log..." &lt;&lt; number1;
      BOOST_LOG_TRIVIAL(info) &lt;&lt; "This message should also go to category 1 log on the same line..." &lt;&lt; number1;
  
      return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>The output written to <code>category1.log</code> shows that a newline was applied between the two calls to <code>BOOST_LOG_TRIVIAL</code>, even though I explicitly set <code>auto_flush</code> to false in the <code>init()</code> function:</p>
  
  <pre><code>This message should go to category 1 log...42
  This message should also go to category 1 log on the same line...42
  </code></pre>
  
  <p>I also use <code>BOOST_LOG_CHANNEL_SEV</code> to log to multiple files, but setting <code>auto_flush</code> to false still appears to have no effect...</p>
  
  <ol>
  <li>How do you disable <code>auto_flush</code>, and have consecutive log statements print to the same line in the log file?</li>
  <li>Can a solution be scaled to multiple log files, such that you can enable <code>auto_flush</code> for some files, but not others?</li>
  </ol>