我想知道是否有类似于FLAGS_stderrthreshold
的东西只输出比boost库中的标志更严重的级别。例如,我下面的代码将所有内容打印到控制台。我可以设置级别,以便它只打印警告,错误和致命吗?
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
int main() {
using namespace boost::log::trivial;
boost::log::sources::severity_logger< severity_level > lg;
BOOST_LOG_SEV(lg, trace) << "A trace severity message";
BOOST_LOG_SEV(lg, debug) << "A debug severity message";
BOOST_LOG_SEV(lg, info) << "An informational severity message";
BOOST_LOG_SEV(lg, warning) << "A warning severity message";
BOOST_LOG_SEV(lg, error) << "An error severity message";
BOOST_LOG_SEV(lg, fatal) << "A fatal severity message";
return 0
}
实际输出:
[2014-03-13 22:21:55.734957] [0xc00001d6] [trace] A trace severity message
[2014-03-13 22:21:55.735957] [0xc00001d6] [debug] A debug severity message
[2014-03-13 22:21:55.735957] [0xc00001d6] [info] An informational severity message
[2014-03-13 22:21:55.735957] [0xc00001d6] [warning] A warning severity message
[2014-03-13 22:21:55.735957] [0xc00001d6] [error] An error severity message
[2014-03-13 22:21:55.735957] [0xc00001d6] [fatal] A fatal severity message
Press any key to continue . . .
欲望输出:
[2014-03-13 22:21:55.735957] [0xc00001d6] [warning] A warning severity message
[2014-03-13 22:21:55.735957] [0xc00001d6] [error] An error severity message
[2014-03-13 22:21:55.735957] [0xc00001d6] [fatal] A fatal severity message
答案 0 :(得分:5)
好的找到了。 :d
boost::log::core::get()->set_filter (
boost::log::trivial::severity >= boost::log::trivial::warning
);
http://www.boost.org/doc/libs/1_54_0_beta1/libs/log/example/doc/tutorial_trivial_flt.cpp