有没有办法用 Boost.Log 实现多个独立的日志系统?

Is there a way to implement multiple independent logging systems with Boost.Log?

Boost.Log 使用全局单例“core”对象,所有日志消息都通过该对象传递。那么,在具有有效独立且可单独配置的日志堆栈的单独线程上执行两个独立任务似乎并不简单。

例如,假设 class A 和 class B 都调用了 class C,并且所有三个 class 都执行了日志记录。但是,我希望将 class A 发起的工作记录到文件 "a.log",并将 class B 发起的工作记录到文件 "b.log"。 在 Boost.Log 中是否有一种惯用的方法来实现这个结果?

我的应用程序是动态链接的 C++,基于 VC++ 2015/Windows 和 GCC 4.8.4/Ubuntu.

是的,Boost.Log 通过属性和过滤支持此用例。基本上,您需要做的是拥有两个文件接收器 - a.log 和 b.log。在每个接收器中,您需要设置一个过滤器,该过滤器将只传递以特殊方式标记的日志记录 - 通过具有特殊属性值。然后将记录器添加到 类 A 和 B,并确保记录器具有您在设置的过滤器中检查的具有不同值的特殊属性。

这个场景是用channel loggers in Boost.Log. The channel logger has an attribute called "Channel", which identifies the source of the log records. You can construct filters using the "Channel" attribute with lambda expressions or with your custom function实现的。