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

1

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?

Kinlaw answered 20/1, 2014 at 19:45 Comment(1)
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)Gibbosity
R
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.

Relict answered 17/9, 2014 at 17:29 Comment(3)
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.Amory
@Amory 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: boost.org/doc/libs/1_58_0/libs/log/doc/html/log/tutorial/…Relict
I am going to give up on using it, I am trying to set it up and it is too difficultHobo

© 2022 - 2024 — McMap. All rights reserved.