1

我正在使用这样的 boost-log 库:

BOOST_LOG_TRIVIAL(info) << "My sample output";

我希望,我不需要改变这一点。

输出看起来像这样

[2013-10-31 17:19:19.044701] [0x3f1e6740] [info]    My sample output

问题:

我正在尝试将此从标准输出转发到文件。

当我尝试这样的事情时

boost::log::add_file_log("sample.log", boost::log::keywords::auto_flush = true);
boost::log::add_common_attributes();

完全相同的输出BOOST_LOG_TRIVIAL看起来像

My sample output

我该怎么做才能找回我心爱的元信息?

4

1 回答 1

0

在花了很多时间尝试之后,我自己想通了。

我只是添加了

boost::log::register_simple_formatter_factory< boost::log::trivial::severity_level, char >("Severity");
boost::log::add_common_attributes();
boost::log::add_file_log("sample.log",
                         boost::log::keywords::auto_flush = true,
                         boost::log::keywords::format = "[%TimeStamp%] [%ProcessID%] [%ThreadID%] [%Severity%]: %Message%" );

作为第一行之一。这会将日志写入 sample.log

关键似乎是add_file_log覆盖了 BOOST_LOG_TRIVIAL 的样式。添加我自己的boost::log::keyword::format解决了这个问题。

于 2013-11-01T13:45:42.547 回答