7

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?

Romain Deterre
  • 546
  • 4
  • 16
  • I suppose you could always store a local copy the logged string in parallel somewhere else (which is what we do in our wrapper for boost.log) – Jay Jan 29 '14 at 16:41

1 Answers1

4

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.

Nathan Monteleone
  • 5,430
  • 29
  • 43
  • 2
    Where the hell is all of this documented? I find Boost.Log incredibly complex and confusing, but their documentation isn't exactly helpful. I've seen no information in the docs on how to use the `record_view` object. – void.pointer Aug 03 '15 at 21:48
  • @void.pointer It's been too long, I have no idea where I found this initially :) It does show up in one of the examples under Log Record Formatting / Custom Formatting Functions: http://www.boost.org/doc/libs/1_58_0/libs/log/doc/html/log/tutorial/formatters.html#log.tutorial.formatters.custom_formatting_functions – Nathan Monteleone Aug 11 '15 at 12:46
  • I am going to give up on using it, I am trying to set it up and it is too difficult – Germán Diago Jun 23 '16 at 10:28