In fact the above channels (names) could be created on the fly. I do not know a-priori what the channels will be so I can use the usual filter examples:
Instead I need to support something else that logically looks like the following
sink->set_filter
(
// Not valid boost.log filter
((has_channel_attribute() ? is_channel_logged(log_record.channel_name(), log_record.severity()) : true) &&
// other filters
);
My function is_channel_logged() needs to take the channel name as an argument and look elsewhere (e.g. look up in the application configuration) whether this channel meets the severity level requirements for being logged.
Looking at the documentation it looks like satisfies is kind of what I need, however, I need to take 2 arguments: channel_name and severity_level in my user-defined predicate.
bool check_severity_level(int level);
sink->set_filter
(
flt::attr< int >("Severity").satisfies(&check_severity_level)
);
This doesn't seem to quite fit the original use case for channels but it is the closest thing I have.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Currently you have to write your own filter. The filter accepts a view of all attribute values that are going to be attached to the log record; the view will include both the channel name and severity level. I don't have an example at hand now but you can take a look at library-provided filters (e.g. has_attr) for guidance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi I'd like to achieve the equivalent of having multiple channel_severity loggers each with their own filter.
So for example,
In fact the above channels (names) could be created on the fly. I do not know a-priori what the channels will be so I can use the usual filter examples:
Instead I need to support something else that logically looks like the following
My function is_channel_logged() needs to take the channel name as an argument and look elsewhere (e.g. look up in the application configuration) whether this channel meets the severity level requirements for being logged.
Looking at the documentation it looks like satisfies is kind of what I need, however, I need to take 2 arguments: channel_name and severity_level in my user-defined predicate.
This doesn't seem to quite fit the original use case for channels but it is the closest thing I have.
Currently you have to write your own filter. The filter accepts a view of all attribute values that are going to be attached to the log record; the view will include both the channel name and severity level. I don't have an example at hand now but you can take a look at library-provided filters (e.g. has_attr) for guidance.
Thanks, I will give it a try and drop a not as to how it went.