我是boost-log的新手,并试图让trivial logging with filters示例与boost-log 1.1一起使用。代码如下所示:
#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";
}
使用clang进行编译会产生以下错误消息:
/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
看起来该示例基于较旧版本的boost-log,并且某些名称已更改。这个例子可以轻松修复吗?但是,似乎没有更新的教程。
答案 0 :(得分:5)
文档中的示例似乎在包含后忽略了以下几行:
namespace logging = boost::log;
namespace filters = boost::log::filters;