Reputation: 3505
Boost.Log uses a global singleton "core" object through which all log messages pass. It seems then, that it would not be straightforward to have two independent tasks on separate threads with effectively independent and separately configurable logging stacks.
For example, suppose class A and class B both call class C, and all three classes perform logging. However, I'd like the work initiated by class A to be logged to file "a.log", and the work initiated by class B to be logged to file "b.log". Is there an idiomatic way to achieve this outcome in Boost.Log?
My application is dynamic linked C++, built on VC++ 2015/Windows and GCC 4.8.4/Ubuntu.
Upvotes: 1
Views: 474
Reputation: 10614
Yes, Boost.Log supports this use case through attributes and filtering. Basically, what you need to do is to have two file sinks - for a.log and b.log. In each sink you need to set up a filter that will only pass log records marked in a special way - by having an special attribute value. Then you add loggers to classes A and B and make sure the loggers have the special attribute with distinct values that you check for in the filters you've set.
This scenario is implemented with 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.
Upvotes: 1