Boost:Log
lastmod 2018-08-17created 2015-03-1919 edits
bjam build command
You can define configuration macros in the bjam command line, like this:
$ bjam --with-log variant=release define=BOOST_LOG_WITHOUT_EVENT_LOG define=BOOST_LOG_USE_WINNT6_API stage
File name format
If you want to apply date_time_numbering to the file name, enter it as follows.
Severity format attribute
If you want to use the %Severity% attribute in Format, apply it as follows.
#include <boost/log/utility/setup/formatter_parser.hpp>
// ...
boost::log::register_simple_formatter_factory< boost::log::trivial::severity_level, char >("Severity");
Common attributes
If you want to use default attributes such as %TimeStamp% in Format, you must initialize as follows.
Custom sink
Simple example:
#include <boost/log/trivial.hpp>
#include <boost/log/sinks/basic_sink_backend.hpp>
#include <boost/log/attributes/value_extraction.hpp>
#include <boost/log/sinks/async_frontend.hpp>
// ...
class app_launcher: public boost::log::sinks::basic_formatted_sink_backend<char,
boost::log::sinks::synchronized_feeding>
{
public:
// The function consumes the log records that come from the frontend
void consume(boost::log::record_view const& rec, string_type const& command_line)
{
std::cout << command_line << std::endl;
}
};
// ...
typedef sinks::synchronous_sink<app_launcher> sink_t;
boost::shared_ptr<sink_t> sink(new sink_t());
boost::shared_ptr<boost::log::core> logc = boost::log::core::get();
logc->add_sink(sink);
Warning
BOOST_LOG_WITHOUT_EVENT_LOG
In case if message compiler detection fails for some reason, you can explicitly disable support for event log backend by defining the BOOST_LOG_WITHOUT_EVENT_LOG configuration macro when building the library.
BOOST_LOG_USE_WINNT6_API
Affects compilation of both the library and users' code. This macro is Windows-specific. If defined, the library makes use of the Windows NT 6 (Vista, Server 2008) and later APIs to generate more efficient code. This macro will also enable some experimental features of the library. Note, however, that the resulting binary will not run on Windows prior to NT 6. In order to use this feature Platform SDK 6.0 or later is required.
Troubleshooting
A summary of problems that occur while using Boost.log and how to solve them.
swprintf not declared
When using MinGW, the following message may be printed.
c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cwchar:159: error:
'::swprintf' has not been declared
c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cwchar:166: error:
'::vswprintf' has not been declared
In this case, enter the following before stdio.h.
undefined reference to boost::detail::set_tss_data
See also: Boost:Thread#Troubleshooting
See also
Favorite site
- Boost.log Advaced usage
- Using boost log
- Adding more information to log: Attributes
- A simple, customized logger, based on Boost.Log v2
Documentation
- Chapter 1. Boost.Log v2
- Setting up sinks
- [Recommended] Utilities
- Attributes
- Filtering revisited
- Log record formatting
- [Recommended] Sink backends