gpt4 book ai didi

c++ - 为什么我的格式在 boost 日志中不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:07:17 26 4
gpt4 key购买 nike

我在这个函数中使用了 boost::log:

#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/utility/setup/file.hpp>

void InitLog() {
logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::debug);
logging::add_file_log(
keywords::file_name = AppHolder::Instance().config().log_folder + "/sign_%Y-%m-%d_%H-%M-%S.%N.log",
keywords::rotation_size = 10 * 1024 * 1024,
keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),
keywords::format = "%TimeStamp% (%LineID%) <%Severity%>: %Message%"
);
}

然后,调用:

BOOST_LOG_TRIVIAL(info) << "thread id: " << this_thread::get_id() << " Initialization succeeded";

输出不符合预期:timestampline idseverity 为空。

() <>: thread id: 7f58e30e8740 Initialization succeeded

最佳答案

您必须向日志核心注册这些属性。像这样:

boost::log::add_common_attributes();

或手动:

boost::log::core::get()->add_global_attribute("TimeStamp", boost::log::attributes::local_clock());
// etc...

关于c++ - 为什么我的格式在 boost 日志中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20352584/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com