I'm trying to get Boost.Log going in my project. The problem comes in the following line from the trivial example:

using namespace boost::log;
core::get()->set_filter
(
    trivial::severity >= trivial::info
);

In my code, this translates to the following:

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

However, I get the following errors:

error C2039: 'severity' : is not a member of 'boost::log::v2s_mt_nt5::trivial'
error C2065: 'severity' : undeclared identifier

I'm kind of searching around the namespaces trying to find out how I'm supposed to do this, but I'm not really finding anything that works. It seems it's some crazy lambda function required for this. I'm alright with some alternative (defining a function that fills in the filtering level?), but I'm not sure how to accomplish this. Any ideas?

I'm using Boost.Log version 2.0-r862, and Boost 1.53.0.

SOLUTION: Ryan pointed out that I should check my includes, and sure enough I was only including trivial.hpp, but core.hpp and expressions.hpp are also required as includes. Including them solved the problem.

// need at least these 3 to get "trivial" to work
#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/trivial.hpp>
有帮助吗?

解决方案

Looking at trivial.hpp, it appears severity is part of the keywords namespace. Did you try boost::log::keywords::severity?

其他提示

Here is a full working example in C++11, that summarizes @aardvarkk solution:

#include <boost/log/expressions.hpp>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>

namespace logging = boost::log;

auto init() -> void
{
    logging::core::get()->set_filter
    (
        logging::trivial::severity >= logging::trivial::warning
    );
}

auto main(int argn, char *args[]) -> int
{
    init();

    BOOST_LOG_TRIVIAL(info) << "Testing the log system";
    BOOST_LOG_TRIVIAL(error) << "Testing the log error";


    return 0;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top