Search code examples
boost-log

How to log line number of coder in boost log 2.0?


Can I use LineID attribute for this? I hope I could use sink::set_formatter to do this instead of using

__LINE__

and

__FILE__

in each log statement.


Solution

  • I struggled with this, until I found this snippet

    #define LFC1_LOG_TRACE(logger) \
    BOOST_LOG_SEV(logger, trivial::trace) << "(" << __FILE__ << ", " << __LINE__ << ") "
    

    Works like a charm