2013-10-31 21 views
1

我使用升压日志库是这样的:转发升压日志以文件降元信息

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 

我能做些什么让我心爱的元信息后面的输出?

回答

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解决了这个问题。