为什么我的格式在升压日志中不起作用

时间:2013-12-03 13:33:03

标签: c++ boost boost-log

我在此功能中使用boost::log

#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/utility/setup/file.hpp>

void InitLog() {
  logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::debug);
  logging::add_file_log(
            keywords::file_name = AppHolder::Instance().config().log_folder + "/sign_%Y-%m-%d_%H-%M-%S.%N.log",
            keywords::rotation_size = 10 * 1024 * 1024,
            keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),
            keywords::format = "%TimeStamp% (%LineID%) <%Severity%>: %Message%"
            );
}

然后,给出电话:

BOOST_LOG_TRIVIAL(info) << "thread id: " << this_thread::get_id() << " Initialization succeeded";

输出不符合预期:时间戳行ID 严重性为空。

  

()&lt;&gt ;:线程ID:7f58e30e8740初始化成功

2 个答案:

答案 0 :(得分:11)

您必须使用日志核心注册这些属性。像这样:

boost::log::add_common_attributes();

或手动:

boost::log::core::get()->add_global_attribute("TimeStamp", boost::log::attributes::local_clock());
// etc...

答案 1 :(得分:4)

添加后,问题解决了。

  

升压::登录:: register_simple_formatter_factory&LT;   boost :: log :: trivial :: severity_level,char&gt;(“Severity”);

完整代码位于我的博客中 use boost log step 4