I have been successfully using the Boost Log library in my project. In other words, I am emitting log messages via BOOST_LOG_TRIVIAL(info) << "My message";
Now I want to control the severity of logging, and I followed the example from the Boost Log library documentation:
#include <boost/log/trivial.hpp>
#include <boost/log/core.hpp>
namespace logging = boost::log;
void init()
{
logging::core::get()->set_filter
(
logging::trivial::severity >= logging::trivial::info
);
}
However, I am getting this compilation error:
main.cpp:22:25: error: ‘severity’ is not a member of ‘boost::log::v2s_mt_posix::trivial’
22 | logging::trivial::severity >= logging::trivial::info
Here is the relevant section of my CMakeLists.txt:
SET(Boost_USE_STATIC_LIBS ON)
find_package(Boost 1.71 COMPONENTS log graph REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(ls_router main.cpp)
target_link_libraries(ls_router PUBLIC ${Boost_LIBRARIES} pthread)
I am on Ubuntu and installed Boost via sudo apt install libboost-all-dev
.
dpkg -l | grep libboost-log
ii libboost-log-dev 1.71.0.0ubuntu2 amd64 C logging library (default version)
ii libboost-log1.71-dev 1.71.0-6ubuntu6 amd64 C logging library
ii libboost-log1.71.0 1.71.0-6ubuntu6 amd64 C logging library
According to this SO question, this might be a CMake configuration issue. Boost.Log with CMake causing undefined reference error. However, none of the suggestions in the question solved my issue.
CodePudding user response:
The severity
keyword is defined in boost/log/detail/trivial_keyword.hpp
. Apparently it's not being included.
The minimal set of includes I could find:
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
namespace logging = boost::log;
void init()
{
logging::core::get()->set_filter(logging::trivial::severity >=
logging::trivial::info);
}
int main() { init(); }
According to this SO question, this might be a CMake configuration issue
That's about linker errors, which this isn't.