如何更改默认使用的boost ::登录:: BOOST_TRIVIAL_LOG格式化? [英] How to change the default formatting with boost::log::BOOST_TRIVIAL_LOG?
问题描述
的boost ::日志看起来真的很强大。它提供了微不足道的日志记录BOOST_LOG_TRIVIAL宏。但我怎么能更改默认的格式?它打印默认情况下,时间戳,由我不希望它。你有什么主意吗?看来唯一的办法就是定义一个新的水槽前从头并将其添加到核心,那么你可以调用set_format()在后端的情况。但是,这不是微不足道了。
boost::log looks really powerful. It offers a BOOST_LOG_TRIVIAL macro for trivial logging. But how can I change the default formatting? It prints the timestamp by default, by I don't want it. Do you have any idea? It seems the only way is to define a new sink ex-novo and add it to the core, then you can call set_format() on the backend in case. But this is no "trivial" anymore.
推荐答案
Boost.Log有一个默认的水槽,只要你不提供自己的散热器所使用。
下面code片段通过添加新下沉的变化控制台日志的格式。
Boost.Log has a default sink, which is used as long as you do not provide your own sink. The following code snippet changes the format of the console-log by adding a new sink.
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/console.hpp>
int main()
{
boost::log::add_console_log(std::cout, boost::log::keywords::format = ">> %Message%");
BOOST_LOG_TRIVIAL(info) << "Hello world!";
}
请注意,你必须在log_setup库添加到您的构建,即做一个
Note that you have to add the log_setup library to your build i.e. do a
-lboost_log_setup -lboost_log
,其中库的顺序是非常重要的。
where the order of the libs is important.
这篇关于如何更改默认使用的boost ::登录:: BOOST_TRIVIAL_LOG格式化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!