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 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With