提升日志记录集输出级别
Posted
技术标签:
【中文标题】提升日志记录集输出级别【英文标题】:Boost logging set output level 【发布时间】:2014-03-14 05:25:03 【问题描述】:我想知道是否有类似于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
【问题讨论】:
【参考方案1】:好的,找到了。 :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
【讨论】:
以上是关于提升日志记录集输出级别的主要内容,如果未能解决你的问题,请参考以下文章