3

I was wondering if there is a something similar to FLAGS_stderrthreshold that only outputs the level that is more severe than the flag in boost library. For example, the code I have below prints everything to the console. Can I set the level so that it only prints warning, error and fatal?

#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
int main() {
    using namespace  boost::log::trivial;
    boost::log::sources::severity_logger< severity_level > lg;
    BOOST_LOG_SEV(lg, trace) << "A trace severity message";
    BOOST_LOG_SEV(lg, debug) << "A debug severity message";
    BOOST_LOG_SEV(lg, info) << "An informational severity message";
    BOOST_LOG_SEV(lg, warning) << "A warning severity message";
    BOOST_LOG_SEV(lg, error) << "An error severity message";
    BOOST_LOG_SEV(lg, fatal) << "A fatal severity message";
    return 0
}

Actual Output:

[2014-03-13 22:21:55.734957] [0xc00001d6] [trace]   A trace severity message
[2014-03-13 22:21:55.735957] [0xc00001d6] [debug]   A debug severity message
[2014-03-13 22:21:55.735957] [0xc00001d6] [info]    An informational severity message
[2014-03-13 22:21:55.735957] [0xc00001d6] [warning] A warning severity message
[2014-03-13 22:21:55.735957] [0xc00001d6] [error]   An error severity message
[2014-03-13 22:21:55.735957] [0xc00001d6] [fatal]   A fatal severity message
Press any key to continue . . .

Desire Output:

[2014-03-13 22:21:55.735957] [0xc00001d6] [warning] A warning severity message
[2014-03-13 22:21:55.735957] [0xc00001d6] [error]   An error severity message
[2014-03-13 22:21:55.735957] [0xc00001d6] [fatal]   A fatal severity message
4

1 回答 1

9

Okay found it. :D

boost::log::core::get()->set_filter (
    boost::log::trivial::severity >= boost::log::trivial::warning
    );

http://www.boost.org/doc/libs/1_54_0_beta1/libs/log/example/doc/tutorial_trivial_flt.cpp

于 2014-03-14T06:25:12.790 回答