提升日志选择目标文件
Boost log select destination file
是否可以使用一个 Boost 日志实例登录 severeal 文件。
我的意思是是否可以指定日志将写入哪个文件:
BOOST_LOG_..(...) << "aaa" <- go to **A.log**
BOOST_LOG_..(...) << "bbb" <- go to **B.log**
是的,这是可能的 - 使用过滤器。
如何执行此操作完全取决于您的首选项,但下面是一个包含作用域记录器标记的示例:
void SomeFunction()
{
{
// everything in this scope gets logged to A.log
BOOST_LOG_SCOPED_LOGGER_TAG(lg, "Log", std::string, "LogA")
BOOST_LOG(lg) << "aaa";
BOOST_LOG(lg) << "aaa2";
}
{
// everything in this scope gets logged to B.log
BOOST_LOG_SCOPED_LOGGER_TAG(lg, "Log", std::string, "LogB")
BOOST_LOG(lg) << "bbb";
BOOST_LOG(lg) << "bbb2";
}
}
// This is your log initialization routine
void InitLogs()
{
// Initialize sinkA to use a file backend that writes to A.log and sinkB to B.log.
// ...
// ...
// Make sink A only accept records with the Log attribute "LogA"
// while sink B will only accept records where it is "LogB".
sinkA.set_filter(flt::attr<std::string>("Log") == "LogA");
sinkB.set_filter(flt::attr<std::string>("Log") == "LogB");
}
相关文章:
- 如何找到目标文件 *.o 的 ram rom 使用情况(.bss .text .rodata .data)?
- 如何使用cmake从主要的CMakeList.txt复制目标文件?
- 可变参数模板在目标文件中有重复的符号?
- 在 Linux 上,目标文件比在 macOS 或 Windows 上大 2.5 倍
- 为什么即使链接器找到目标文件,我的程序也看不到函数定义?
- 从.o目标文件中提取函数的原始机器代码?
- Cmake:如何引用链接到多个程序的目标文件中的文件?
- 为什么内部链接的名称会出现在我的目标文件的符号表中?
- C++多个目标文件中的模板和编译
- 如果目标文件已经具有标头保护,我们是否应该用 #ifndef 来保护 #include
- Xcode 找不到目标文件
- 源外生成与目标文件的规则不匹配
- 链接 C 和C++目标文件
- nm 获取整个存档的未定义符号,而不是单独的目标文件
- 何时在带有头文件和目标文件的类方法中使用“inline”关键字
- 如何使用同一头文件编译和链接C++中的目标文件
- 源代码构建中的 SCons 仅适用于可执行程序,不适用于目标文件
- 代码::块不制作目标文件
- 粘附 C 和C++目标文件而不带源代码
- 如何在cmake中使用不同的命令和.exe不同的命令制作目标文件