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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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!";
}
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.