Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost logging - destinations and formatters

I am having a problem with using Boost Logging library, that if I add a formatter or a destination to a logger, using my own Log class, I cannot change that destination or formatter.

Does anybody know how to change the destination or formatter on a boost log object?

The scenario I have is that I want a different destination (file name) for each request my server component handles, so I need to have flexible way to change them. Also the fact that I will be logging from different thread simultanuously, and each Log should really have it's own destination's, easily added - removed.

The fact that with the macro's the logging objects are really app global, does not really aid this.

Can anybody give me some guidance on how I can create a flexible way to add/remove destinations to a Logger from boost::logging?

like image 233
Tony The Lion Avatar asked Nov 05 '22 05:11

Tony The Lion


1 Answers

Ok, here's what I would try. It might work for you. It looks as if the logging library is tailored for global loggers, while you are wanting to use thread-local loggers. I'd look up how to create a logger on demand (i.e. directly), for example by analysing BOOST_DECLARE_LOG. Then you can declare a std::map<int, Logger> that you use to map thread-id to specific logger. Probably you can create your own wrapper class that handles this transparently for client code. Then you just log using your own logging layer and create thread-specific loggers when needed. If you need to remove them after your request is finished you can add a method to do this.

Hope this helps!

like image 93
Daniel Lidström Avatar answered Nov 11 '22 21:11

Daniel Lidström