0

我对 Boost.Log 有一些问题:这是一个片段:

#include <boost/date_time/posix_time/posix_time_types.hpp>
#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>

int main()
{
    namespace logging = boost::log;
    namespace src = boost::log::sources;
    namespace expr = boost::log::expressions;
    namespace keywords = boost::log::keywords;
    namespace sinks = boost::log::sinks;

    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% [%Uptime%] (%LineID%) <%Severity%>: %Message%"
     );

   BOOST_LOG_TRIVIAL( trace ) << "Message";

   return 0;

}

我有以下输出:

[] () <>: Message

似乎格式不起作用......我错了吗?

4

1 回答 1

1

尽管您的问题不完整,但我的猜测是您缺少属性定义,即在设置日志文件后尝试添加以下内容:

logging::add_common_attributes();

于 2014-01-28T19:10:14.857 回答