title: C++ Pass Boost::log severity level as argument to function
body: <p>I want to have only one function to write logs which would parse ellipsis and send result to the Boost::log, based on severity level. In header file would be defined different macros, which would select a correct severity level. There is the code:</p>
  
  <pre><code>#include &lt;boost/log/core.hpp&gt;
  #include &lt;boost/log/trivial.hpp&gt;
  #include &lt;boost/log/expressions.hpp&gt;
  
  #define DEBUG(msg, ...)         Logger::write_log(debug,   msg, ##__VA_ARGS__);
  #define INFO(msg, ...)          Logger::write_log(info,    msg, ##__VA_ARGS__);
  #define WARNING(msg, ...)       Logger::write_log(warning, msg, ##__VA_ARGS__);
  #define ERROR(msg, ...)         Logger::write_log(error,   msg, ##__VA_ARGS__);
  
  namespace logging   = boost::log;
  
  void write_log(auto level, const char *message, ...)
  {
      char buffer[512];
      va_list args;
  
      // Parse ellipsis and add arguments to message
      va_start (args, message);
      vsnprintf (buffer, sizeof(buffer), message, args);
      va_end (args);
  
      BOOST_LOG_TRIVIAL(level) &lt;&lt; buffer;
  }
  
  int main(int argc, char** argv)
  {
      DEBUG("Test string %s", "additional string");
  
      return 0;
  }
  </code></pre>
  
  <p>But during compilation I get the next error:</p>
  
  <pre><code> error: 'level' is not a member of 'boost::log::v2s_mt_nt5::trivial'
           BOOST_LOG_TRIVIAL(level) &lt;&lt; buffer;
  </code></pre>
  
  <p>Seems that my level argument have an incorrect type. I also tried to use <code>logging::trivial::severity_level level</code> instead of <code>auto level</code>, but this didn't help. How can I fix this error?</p>
  
  <p>UPDATED:</p>
  
  <p>there is working solution:</p>
  
  <pre><code>#include &lt;boost/log/core.hpp&gt;
  #include &lt;boost/log/trivial.hpp&gt;
  #include &lt;boost/log/expressions.hpp&gt;
  
  #define DEBUG(msg, ...)         Logger::write_log(debug,   msg, ##__VA_ARGS__);
  #define INFO(msg, ...)          Logger::write_log(info,    msg, ##__VA_ARGS__);
  #define WARNING(msg, ...)       Logger::write_log(warning, msg, ##__VA_ARGS__);
  #define ERROR(msg, ...)         Logger::write_log(error,   msg, ##__VA_ARGS__);
  
  namespace logging   = boost::log;
  
  enum severity_level
  {
      debug,
      info,
      warning,
      error,
      exception
  };
  src::severity_logger&lt;severity_level&gt; slg;
  
  void write_log(severity_level level, const char *message, ...)
  {
      char buffer[512];
      va_list args;
  
      // Parse ellipsis and add arguments to message
      va_start (args, message);
      vsnprintf (buffer, sizeof(buffer), message, args);
      va_end (args);
  
      BOOST_LOG_SEV(slg, level) &lt;&lt; buffer;
  }
  
  int main(int argc, char** argv)
  {
      DEBUG("Test string %s", "additional string");
  
      return 0;
  }
  </code></pre>