gpt4 book ai didi

c++ - 将 Boost 日志转发到文件会丢弃元信息

转载 作者:太空宇宙 更新时间:2023-11-04 14:00:01 25 4
gpt4 key购买 nike

我正在像这样使用 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

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

最佳答案

在花了很多时间尝试之后,我自己弄明白了。

我只是加了

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

关于c++ - 将 Boost 日志转发到文件会丢弃元信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19712112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com