提升日志文件无效

时间:2015-05-02 23:59:16

标签: c++ boost boost-log

我无法弄清楚为什么这个示例代码无法正常工作。我的编译器说被调用的函数不是声明的命名空间的成员。这是Boost日志的示例代码,为什么它不起作用?我需要做什么?

我已经定义了BOOST_LOG_DYN_LINK,并且我已经包含了所有标题,这些标题应该被包含在内。另外,通过yum从fedora repos安装了boost,根据yum,提升版本为1.55.0

示例:http://www.boost.org/doc/libs/1_55_0/libs/log/example/doc/tutorial_file.cpp

错误

main.cpp:33:5: error: ‘add_file_log’ is not a member of ‘logging’
     logging::add_file_log(
     ^
main.cpp:34:10: error: ‘file_name’ is not a member of ‘keywords’
          keywords::file_name = "sample_%N.log",                                        /*< file name pattern >*/
          ^
main.cpp:35:10: error: ‘rotation_size’ is not a member of ‘keywords’
          keywords::rotation_size = 10 * 1024 * 1024,                                   /*< rotate files every 10 MiB... >*/
          ^
main.cpp:36:10: error: ‘time_based_rotation’ is not a member of ‘keywords’
          keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), /*< ...or at midnight >*/
          ^
main.cpp:36:49: error: ‘sinks::file’ has not been declared
          keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), /*< ...or at midnight >*/

代码

#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>

namespace logging = boost::log;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace keywords = boost::log::keywords;

void init()
{
    logging::add_file_log
    (
        keywords::file_name = "sample_%N.log",
        keywords::rotation_size = 10 * 1024 * 1024,
        keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),
        keywords::format = "[%TimeStamp%]: %Message%"
    );

    logging::core::get()->set_filter
    (
        logging::trivial::severity >= logging::trivial::info
    );
}

进行调用

g++ -c -DBOOST_LOG_DYN_LINK -o main.cpp.o main.cpp

链接器标记:-lboost_program_options -lboost_log -lboost_filesystem -lboost_system -lboost_thread -lpthread

详细日志:https://gist.github.com/HSchmale16/d4dd5656a47ce82c63b2

1 个答案:

答案 0 :(得分:1)

检查头文件是否缺少任何内容,并在编译器/链接器调用中包含-lboost_log_setup。