Boost.Log failed to set registration filter (undeclared identifier "severity")

I am trying to get Boost.Log in my project. The problem occurs in the following line from a trivial example:

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

In my code, this means 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 kind of looked around namespaces, trying to figure out how I should do this, but I really can't find anything that works. This seems to require some kind of crazy lambda function. I'm fine with some kind of alternative (defining a function that fills the filtering level?), But I'm not sure how to do this. Any ideas?

I am using Boost.Log version 2.0-r862 and Boost 1.53.0.

SOLUTION Ryan pointed out that I should check my included data, and of course I only included trivial.hpp , but there should also be core.hpp and expressions.hpp . Including they 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> 
+6
source share
2 answers

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

+2
source

Here is a complete working example in C ++ 11 that summarizes @aardvarkk's 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; } 
0
source

Source: https://habr.com/ru/post/944072/


All Articles