1

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.

1 Answer 1

1

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.

1
  • Thanks, that seems like a good approach. this answer to a different question (also by @andrey) turns out to be pretty much the same way of attacking the problem. I think I'll be able to implement what I want to do following your suggestions.
    – Boinst
    Oct 8, 2015 at 23:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.