我使用的boost-log库如下:
BOOST_LOG_TRIVIAL(info) << "My sample output";我希望,我不需要改变这一点。
输出如下所示
[2013-10-31 17:19:19.044701] [0x3f1e6740] [info] My sample output问题是:
我正在尝试将它从stdout转发到一个文件。
当我尝试这样的事情时
boost::log::add_file_log("sample.log", boost::log::keywords::auto_flush = true);
boost::log::add_common_attributes();完全相同的BOOST_LOG_TRIVIAL的输出如下所示
My sample output我可以做些什么来找回我心爱的元信息?
发布于 2013-11-01 21:45:43
在花了很多时间尝试之后,我自己弄明白了。
我只是简单地添加了
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解决了这个问题。
https://stackoverflow.com/questions/19712112
复制相似问题