Tuesday 15 March 2011

c++ - Why does it always print loggers with info severity level? -



c++ - Why does it always print loggers with info severity level? -

i trying understand boost log tutorial, , have written next code:

#include <iostream> #include <boost/log/keywords/severity.hpp> #include <boost/log/sources/record_ostream.hpp> #include <boost/log/sources/severity_feature.hpp> #include <boost/log/sources/severity_logger.hpp> namespace keywords = boost::log::keywords; namespace src = boost::log::sources; // define our own severity levels enum severity_level { normal = 0, notification, warning, error, critical }; void logging_function() { // logger implicitly adds source-specific attribute 'severity' // of type 'severity_level' on construction src::severity_logger< severity_level > slg; boost_log_sev(slg, normal) << "a regular message"; boost_log_sev(slg, warning) << "something bad going on can handle it"; boost_log_sev(slg, critical) << "everything crumbles, shoot me now!"; } void default_severity() { // default severity can specified in constructor. src::severity_logger< severity_level > error_lg(keywords::severity = error); boost_log(error_lg) << "an error level log record (by default)"; // explicitly specified level overrides default boost_log_sev(error_lg, warning) << "a warning level log record (overrode default)"; } int main(int argc, char **argv) { logging_function(); default_severity(); std::cout << "hello, world!" << std::endl; homecoming 0; }

but printing logs info severity level, this:

[2014-11-12 14:38:23.476358] [0xbedaf780] [info] regular message [2014-11-12 14:38:23.476967] [0xbedaf780] [info] bad going on can handle [2014-11-12 14:38:23.476978] [0xbedaf780] [info] crumbles, shoot me now! [2014-11-12 14:38:23.476991] [0xbedaf780] [info] error level log record (by default) [2014-11-12 14:38:23.477002] [0xbedaf780] [info] warning level log record (overrode default) hello, world!

why that? normal print in standard out? , why isn't printing wanted severity level?

even if have added this:

std::ostream& operator<<(std::ostream& strm, severity_level level) { static const char* strings[] = { "normal", "notification", "warning", "error", "critical" }; if (static_cast< std::size_t >(level) < sizeof(strings) / sizeof(*strings)) strm << strings[level]; else strm << static_cast< int >(level); homecoming strm; }

the output remains same. else have forgotten?

c++ logging boost

No comments:

Post a Comment