在添加过滤器之前,一切正常:
Filter="%Severity% > 3"
搜索一下(通过
Boost.Log Configuration Files
e、 g.)我发现:
如何使用init\u from \u settings()配置严重性\u记录器以获取
您必须向
这包括严重性级别枚举。
logging::register_simple_filter_factory<logging::trivial::severity_level>("Severity");
现在,修复过滤器表达式以使用文本表示:
Filter="%Severity% > debug"
need to add the
TimeStamp
attribute to core
:
logging::core::get()->add_global_attribute("TimeStamp", logging::attributes::local_clock());
现在一切正常了:
#include <fstream>
#include <iostream>
#include <boost/log/attributes.hpp>
#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/from_settings.hpp>
#include <boost/log/utility/setup/from_stream.hpp>
#include <boost/log/utility/setup/settings.hpp>
#include <boost/regex.hpp>
namespace logging = boost::log;
namespace keywords = boost::log::keywords;
#define BOOST_LOG_DYN_LINK 1
int main(int, char *[]) {
std::ifstream file("settings.ini");
logging::core::get()->add_global_attribute("TimeStamp", logging::attributes::local_clock());
logging::register_simple_filter_factory<logging::trivial::severity_level>("Severity");
logging::init_from_stream(file);
BOOST_LOG_TRIVIAL(trace) << "This is a trace severity message";
BOOST_LOG_TRIVIAL(debug) << "This is a debug severity message";
BOOST_LOG_TRIVIAL(info) << "This is an informational severity message";
BOOST_LOG_TRIVIAL(warning) << "This is a warning severity message";
BOOST_LOG_TRIVIAL(error) << "This is an error severity message";
BOOST_LOG_TRIVIAL(fatal) << "and this is a fatal severity message";
}
<2018-09-01 00:36:11.972436> - This is an informational severity message
<2018-09-01 00:36:11.972712> - This is a warning severity message
<2018-09-01 00:36:11.972735> - This is an error severity message
<2018-09-01 00:36:11.972747> - and this is a fatal severity message
补充
Demo Live On Coliru