Get severity of boost.log logger..?
Asked Answered
V

1

6

Suppose I have a simple boost.log severity_logger logger set up like this:

   logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::debug);
   logging::add_common_attributes();
   src::severity_logger< logging::trivial::severity_level > logger;

How would I check the severity programmatically?
I.e. somethinig like logger.getSeverity()..?

I've sifted through the docs and other questions here on StackOverflow but just couldn't find what should be a straightforward API call..?

Votary answered 29/1, 2014 at 7:17 Comment(0)
T
5

I would say you cannot. The logging system is layered in three layers (see Design overview of the logging system).

  • Your severity_logger is a source logger with attribute severity_level within the data collection layer.

  • The severity you set with logging::core::get()->set_filter(...) is a function object, that set for the logging core. All messages passed to a logger will get filtered by that function object, before being passed to the sinks.

So, there is actually no such thing as severity is the severity_logger. The severity is just passed to the core and then to the sinks.


EDIT: Elaborating on my comment, you could also declare a variable severityLevel and pass it to the set_filter function (using boost's reference wrapper boost::ref())

// defined somewhere:
logging::trivial::severity_level severityLevel = logging::trivial::info;

// passed to set_filter() by reference
logging::core::get()->set_filter(
    logging::trivial::severity >= boost::ref(severityLevel));

// try out the logging:
BOOST_LOG_SEV(logger, warning) << "A warning severity message"; // not filtered out
severityLevel = logging::trivial::error;
BOOST_LOG_SEV(logger, warning) << "Another warning message"; // filtered out
Trixie answered 29/1, 2014 at 11:40 Comment(2)
Hmm.. interesting. So I'd have to store whatever is passed on to boost.log via set_filter() in my wrapper classVotary
It depends on what you want to achieve. The filter function object could also be initialized with your own function which behavior could depend on some variable (see the class boost::logging::filter).Trixie

© 2022 - 2024 — McMap. All rights reserved.