4 #include <boost/log/sinks/sync_frontend.hpp> 5 #include <boost/log/sinks/text_ostream_backend.hpp> 6 #include <boost/test/unit_test.hpp> 16 .logfile_basename(
"ut_logging"));
18 JB_LOG(trace) <<
"tracing tracing tracing";
19 for (
int i = 0; i != 30000; ++i) {
20 JB_LOG(debug) <<
"i=" << i;
23 JB_LOG(info) <<
"testing my logger (" << 1 <<
")";
24 JB_LOG(warning) <<
"testing warnings in my logger";
27 std::string foo(
"more complex expr test");
31 auto expensive = [](
int n) {
33 for (
int i = 0; i != n; ++i) {
40 JB_LOG(trace) <<
"this never gets to run, and the optimizer " 41 <<
"should remove it" << expensive(20);
42 JB_LOG(debug) <<
"this does not run, but the compiler will keep..." 44 JB_LOG(notice) <<
"L3 x=" << x <<
", foo=" << foo <<
", y=" << y;
45 JB_LOG(warning) <<
"L3 this";
47 JB_LOG(notice) <<
"x=" << x <<
", foo=" << foo <<
" y=" << y;
48 JB_LOG(debug) <<
"x=" << x <<
", foo=" << foo <<
" y=" << y;
49 JB_LOG(error) <<
"x=" << x <<
", foo=" << foo <<
" y=" << y;
51 std::ostringstream os;
52 auto core = boost::log::core::get();
53 auto backend = boost::make_shared<boost::log::sinks::text_ostream_backend>();
54 backend->add_stream(boost::shared_ptr<std::ostream>(&os, [](
void const*) {}));
55 backend->auto_flush(
true);
56 typedef boost::log::sinks::synchronous_sink<
57 boost::log::sinks::text_ostream_backend>
59 auto sink = boost::make_shared<sink_t>(backend);
62 JB_LOG(alert) <<
"this is a log line";
64 BOOST_CHECK_EQUAL(os.str(),
"this is a log line\n");
66 core->remove_sink(sink);
69 JB_LOG(info) <<
"more logging after removing the sunk...";
76 char const contents[] = R
"""(# YAML overrides 77 minimum-severity: ERROR 78 minimum-console-severity: NOTICE 81 std::istringstream is(contents); 89 std::ostringstream os;
90 BOOST_CHECK_NO_THROW(os << tested);
97 char const contents[] = R
"""(# YAML overrides 98 enable-file-logging: true 101 std::istringstream is(contents);
Configuration object for the logging functions.
BOOST_AUTO_TEST_CASE(logging_basic)
void load_overrides(int &argc, char *argv[], std::string const &filename, char const *environment_variable_name)
Read the configuration file and load the overrides defined therein.
void init(config const &cfg)
Initialize the logging functions using the configuration provided.
jb::config_attribute< config, jb::severity_level > minimum_console_severity
A simple class to communicate the result of parsing the options.
jb::config_attribute< config, jb::severity_level > minimum_severity
jb::severity_level minimum_severity