0

我是boost-log 的新手,并试图使带有过滤器的简单日志记录示例与 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 并且某些名称已更改。这个例子可以很容易地修复吗?但是,似乎没有更新的教程。

4

1 回答 1

5

文档中的示例似乎只是在包含后缺少以下几行:

namespace logging = boost::log;
namespace filters = boost::log::filters;
于 2012-01-14T18:03:34.017 回答