I am new to boost-log and tried to make the trivial logging with filters example work with boost-log 1.1. The code looks like this:

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

void init()
{
    logging::core::get()->set_filter
    (
     filters::attr< logging::trivial::severity_level >("Severity") >= logging::trivial::info
     );
}

int main(int, char*[])
{
    BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
}

Compiling this with clang results the following error messages:

/Users/admin/Documents/cmake tests/boost-log/main.cpp:7:5: error: use of undeclared identifier 'logging'
    logging::core::get()->set_filter
    ^
/Users/admin/Documents/cmake tests/boost-log/main.cpp:9:3: error: use of undeclared identifier 'filters'; did you mean 'boost::log_mt_posix::filters'?
         filters::attr< logging::trivial::severity_level >("Severity") >= logging::trivial::info
         ^~~~~~~
         boost::log_mt_posix::filters
/usr/local/include/boost/log/filters/has_attr.hpp:32:11: note: 'boost::log_mt_posix::filters' declared here
namespace filters {
          ^
/Users/admin/Documents/cmake tests/boost-log/main.cpp:9:18: error: use of undeclared identifier 'logging'
         filters::attr< logging::trivial::severity_level >("Severity") >= logging::trivial::info

It looks like the example is based on an older version of boost-log and some names have changed. Can the example be easily fixed? An updated tutorial however does not seem to be available.

有帮助吗?

解决方案

The example in the docs just seems to be missing the following lines after the includes:

namespace logging = boost::log;
namespace filters = boost::log::filters;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top