Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Log level configuration

If you need to enforce specific log level from within your test module use the following interface:

boost::unit_test::unit_test_log.set_threshold_level( boost::unit_test::log_level );

or for a specific logger:

boost::unit_test::unit_test_log.set_threshold_level( boost::unit_test::output_format, boost::unit_test::log_level );
[Tip] Tip

See boost::unit_test::unit_test_log_t::set_threshold_level and boost::unit_test::output_format for more details

In regular circumstances you shouldn't use this interface, since you not only override default log level, but also the one supplied at test execution time. Prefer to use runtime parameters --log_level or --logger for log level selection.

Example: Compile-time log level configuration

Code

#define BOOST_TEST_MODULE example
#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test_parameters.hpp>
using namespace boost::unit_test;

BOOST_AUTO_TEST_CASE( test_case0 )
{
  if( runtime_config::get<log_level>( runtime_config::btrt_log_level ) < log_warnings )
    unit_test_log.set_threshold_level( log_warnings );

  BOOST_WARN( sizeof(int) > 4 );
}

Output

> example
Running 1 test case...
test.cpp(13): warning in "test_case0": condition sizeof(int) > 4 is not satisfied

*** No errors detected

PrevUpHomeNext