8

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严重性为空。

() <>: thread id: 7f58e30e8740 初始化成功

4

2 回答 2

13

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

boost::log::add_common_attributes();

或手动:

boost::log::core::get()->add_global_attribute("TimeStamp", boost::log::attributes::local_clock());
// etc...
于 2013-12-04T15:01:40.683 回答
4

添加后,问题解决了。

boost::log::r​​egister_simple_formatter_factory< boost::log::trivial::severity_level, char >("Severity");

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

于 2013-12-06T09:00:55.047 回答