title: Append to ostream in a preprocessor macro
body: <p>I'd mimick the widespread <code>BOOST_LOG_TRIVIAL</code> with a custom define which uses <code>std::cout</code> instead.</p>
  
  <pre><code>// Building with
  // g++ -std=c++14 -Wall -pedantic -g -O0 -DBOOST_LOG_DYN_LINK -c log.cpp
  // g++ log.o -lpthread -lboost_log -lboost_log_setup  -lboost_system -lboost_thread -o bl
  
  #define FORBID_BOOST_LOG
  #define VALUE_TO_STRING(x) #x
  
  #ifdef FORBID_BOOST_LOG
      #include &lt;iostream&gt;
      #define LOG(sev) std::cout &lt;&lt; "[" &lt;&lt; VALUE_TO_STRING(sev) &lt;&lt; "]  "
  #else
      #include &lt;boost/log/trivial.hpp&gt;
      #define LOG(sev) BOOST_LOG_TRIVIAL(sev)
  #endif
  
  int main()
  {
      LOG(info) &lt;&lt; "hello logging";
  }
  </code></pre>
  
  <p>Which is nice, but the only feature missing here it that nice trailing newline char added by boost trivial logging.</p>
  
  <p>I've read across few boost headers, but actually have no idea about the correct preprocessor syntax to mantain hundreds of <code>LOG(sev)</code> calls agnostic about the preprocessor selected implementation.</p>