In this section we shall walk through the essential steps to get started with
the library. After reading it you should be able to initialize the library
and add logging to your application. The code of this tutorial is also available
in examples residing in the libs/log/examples
directory. Feel free to play around
with them, compile and see the result.
For those who don't want to read tons of clever manuals and just need a simple tool for logging, here you go:
#include <boost/log/trivial.hpp> int main(int, char*[]) { BOOST_LOG_TRIVIAL(trace) << "A trace severity message"; BOOST_LOG_TRIVIAL(debug) << "A debug severity message"; BOOST_LOG_TRIVIAL(info) << "An informational severity message"; BOOST_LOG_TRIVIAL(warning) << "A warning severity message"; BOOST_LOG_TRIVIAL(error) << "An error severity message"; BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message"; }
The BOOST_LOG_TRIVIAL
macro
accepts a severity level and results in a stream-like object that supports
insertion operator. As you can see, this library usage pattern is quite similar
to what you would do with std::cout
.
However, the library offers a few advantages:
It must be said that the macro, along with other similar macros provided by the library, is not the only interface that the library offers. It is possible to issue log records without using any macros at all.