提升日志到文件不起作用
Boost Log to File not working
我不明白为什么这个示例代码不能正常工作。我的编译器说被调用的函数不是声明的命名空间的成员。这是 Boost 日志的示例代码,为什么它不起作用?我需要做什么?
我已经定义了 BOOST_LOG_DYN_LINK
,并且我已经包含了所有应该包含的 headers。此外,boost 是通过 yum
从 fedora repos 安装的,根据 yum,boost 版本是 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
我可以毫无错误地编译它,无需更改代码。检查您的 boost::log 来源以确保您拥有您期望的内容。我的猜测是您的 boost 文件已损坏。相信这个错误表明在编译器查找的地方找不到该函数。
检查您的头文件是否缺少任何内容,并将 -lboost_log_setup 添加到您的 compiler/linker 调用中。
我不明白为什么这个示例代码不能正常工作。我的编译器说被调用的函数不是声明的命名空间的成员。这是 Boost 日志的示例代码,为什么它不起作用?我需要做什么?
我已经定义了 BOOST_LOG_DYN_LINK
,并且我已经包含了所有应该包含的 headers。此外,boost 是通过 yum
从 fedora repos 安装的,根据 yum,boost 版本是 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
我可以毫无错误地编译它,无需更改代码。检查您的 boost::log 来源以确保您拥有您期望的内容。我的猜测是您的 boost 文件已损坏。相信这个错误表明在编译器查找的地方找不到该函数。
检查您的头文件是否缺少任何内容,并将 -lboost_log_setup 添加到您的 compiler/linker 调用中。