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..?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With