为什么我的格式在提升日志中不起作用
why my format doesn't work in boost log
我在这个函数中使用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";
输出不符合预期:时间戳、行id和严重性为空。
()<>:线程id:7f58e30e8740初始化成功
您必须向日志核心注册这些属性。像这样:
boost::log::add_common_attributes();
或手动:
boost::log::core::get()->add_global_attribute("TimeStamp", boost::log::attributes::local_clock());
// etc...
添加这些之后,问题就解决了。
boost::log::register_simple_formatter_factory<boost::log::trial::severity_level,char>("严重性");
完整代码位于我的博客中使用提升日志步骤4
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- 为什么Stroustup书中的has_f不起作用
- 你能检查一下为什么在这个代码中从链接列表中删除项目不起作用吗
- 嵌套While循环不起作用(C++问题)
- C++Matching Brackets 2解决方案不起作用
- boost::从 DLL 调用时日志格式不起作用
- 为什么我的格式在提升日志中不起作用