|
Boost Users : |
Subject: [Boost-users] [Log] Extract severity value
From: Olivier Tournaire (olitour_at_[hidden])
Date: 2014-03-14 20:25:14
Hi all,
I am trying to extract severity level from a log record, but i seems that I
am doing it the wrong way. Here is the code I use:
void LogDockWidget::receiveLog(boost::log::record_view const& rec, const
std::string& log)
{
logging::value_ref< logging::trivial::severity_level > level =
logging::extract< logging::trivial::severity_level >("Severity", rec);
// ...
}
Here level.get() always returns "info". All my logs are done with the
BOOST_LOG_TRIVIAL(...) macro. The formatter whereas displays correctly the
severity level. Here is how it is defined:
void LogDockWidget::init_logging()
{
boost::shared_ptr< logging::core > core = logging::core::get();
typedef sinks::synchronous_sink< QTextEditFormattedSinkBackend > sink_t;
boost::shared_ptr< sink_t > sink(new sink_t);
// ...
logging::add_file_log( keywords::file_name = logFilename,
keywords::auto_flush = true,
keywords::format = ( BUILD_LOG_FORMATTER() )
);
sink->set_formatter( BUILD_LOG_FORMATTER() );
core->add_sink(sink);
// Add attributes that we will use
logging::add_common_attributes();
core->add_global_attribute( "ThreadID", attrs::current_thread_id());
}
#define BUILD_LOG_FORMATTER() \
expr::stream \
<< "[" << expr::format_date_time< boost::posix_time::ptime
>("TimeStamp", "%Y-%m-%d %H:%M:%S") << "] " \
<< expr::attr<unsigned int>("LineID") << " " \
<< ": <" << logging::trivial::severity << "> " \
<< " [" << expr::attr<attrs::current_thread_id::value_type>("ThreadID")
<< "] " \
<< expr::if_(expr::has_attr(scope_attribute)) \
[ \
expr::stream << "[" << scope_attribute << "] " \
] \
<< expr::message
Could you please let me know what I am doing wrong?
Regards,
Olivier
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net