Is it possible to retrieve the logged message as a string from boost::log::record_view?

StackOverflow https://stackoverflow.com/questions/21242762

  •  30-09-2022
  •  | 
  •  

Question

The documentation of record_view states that it encapsulates the log message string.

I'd like to retrieve it in the context of the consume function of a custom basic_string_backend subclass.

Is it possible, or do I have to derive from basic_formatted_sink_backend?

Was it helpful?

Solution

You can get it like this:

void consume(boost::logger::record_view const& rec)
{
    std::string myString = *rec[boost::logger::expressions::smessage];
    // etc...
}

Include boost/logger/expressions.h to get boost::logger::expressions::smessage.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top