squall_coder
squall_coder

Reputation: 59

Boost Log Scoped Log/Attributes not showing up

I'm trying to use Boost Log for my logging framework and I'm having some issues. I have the severity logger working fine. However what I'd like to do is add custom tags to my log messages so I can trace which class/module the message is coming from. Unfortunately no matter what I do the extra traces don't show up!

boost::log::core::get()->add_global_attribute("Scope", boost::log::attributes::named_scope());
BOOST_LOG_NAMED_SCOPE("named_scope_logging");
BOOST_LOG(Logger::get()) << "Hello";
BOOST_LOG_SCOPED_THREAD_TAG("Tag", "Called from A::bar");
BOOST_LOG(Logger::get()) << "Hello";

Basically none of the above produces any sort of modification to the log output. I must be missing something very basic ...

Upvotes: 0

Views: 1135

Answers (1)

Andrey Semashev
Andrey Semashev

Reputation: 10604

You probably forgot to add these attributes to the formatter. For example, the named scope formatter is documented here. The BOOST_LOG_SCOPED_THREAD_TAG adds a string attribute which can be formatted with a simple attr expression. For example:

sink->set_formatter
(
  expr::stream << "["
    << expr::format_named_scope("Scope", keywords::format = "%n")
    << "] ("
    << expr::attr< std::string >("Tag")
    << ") " << expr::smessage
);

Upvotes: 3

Related Questions