Boost logo

Boost :

Subject: Re: [boost] [log] How to set/reset a channel-specific filter
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2010-03-16 12:20:37


On 03/16/2010 02:26 PM, Andreas Huber wrote:
> Hi
>
> We're currently reviewing Boost.Log and are wondering what is the best
> way to implement channel-specific filters. More precisiely, we are
> currently using the following "objects":
>
> - 2 sinks (one to debug output window, one to file)
> - several severity_channel_logger_mt objects, all declared with
> BOOST_LOG_DECLARE_GLOBAL_LOGGER, each of these is guaranteed to have a
> unique channel name
>
> For each of the channels, we would like to set a filter that only
> applies to records logged through the given channel. Since we can't seem
> to set a filter on the logger itself, we're wondering what is the best
> way to accomplish this?
>
> It seems as though both the core as well as the sinks only accept one
> filter. So, it seems we would have to a) assemble a filter expression
> that includes all the channels we'd like to filter on. *Or*, we could b)
> add exactly two sinks per logger object and set the desired filter on
> both sinks. Of course, we'd still want to only log to one file, so the
> question arises whether it is safe to have multiple sinks write to one
> file.

No, two sinks should not access the same file.

> If we go with method a), we'd need a way to enumerate all global
> loggers.

Not sure why would you need to enumerate loggers. You could simply
specify all the channels in the filter, if their number is not very big.
If it is, you can create your own function that accepts the channel name
and then decides if it is enabled. This function can then be converted
into a filter like this:

   bool is_channel_enabled(std::string const& chan_name);

   sink->set_filter(
     flt::attr< std::string >("Channel").satisfies(&is_channel_enabled)
   );


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk