[ 
https://issues.apache.org/jira/browse/LOG4J2-2984?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Samuel Martin updated LOG4J2-2984:
----------------------------------
    Affects Version/s: 2.0
                       2.0.1
                       2.0.2
                       2.1
                       2.2
                       2.3
                       2.4
                       2.4.1
                       2.5
                       2.6
                       2.6.1
                       2.6.2
                       2.7
                       2.8
                       2.8.1
                       2.8.2
                       2.9.0
                       2.9.1
                       2.10.0
                       2.11.0
                       2.11.1
                       2.11.2
                       2.12.0
                       2.12.1
                       2.13.0
                       2.13.1
                       2.13.2
                       2.13.3

> Filters are not applied to loggers
> ----------------------------------
>
>                 Key: LOG4J2-2984
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2984
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Configuration, Documentation, Filters
>    Affects Versions: 2.0, 2.0.1, 2.0.2, 2.1, 2.2, 2.3, 2.4, 2.4.1, 2.5, 2.6, 
> 2.6.1, 2.6.2, 2.7, 2.8, 2.8.1, 2.8.2, 2.9.0, 2.9.1, 2.10.0, 2.11.0, 2.11.1, 
> 2.11.2, 2.12.0, 2.12.1, 2.13.0, 2.13.1, 2.13.2, 2.14.0, 2.13.3
>            Reporter: Samuel Martin
>            Priority: Major
>              Labels: Filtering, Logger
>
> According to the documentation, Filters can be applied in different places: 
> among others, as global filters applied to the whole configuration, to 
> individual Appenders or... to individual loggers. However, when trying to 
> configure a filter within a Logger, it doesn't seem to be applied.
> After debugging the issue, I think I have traced it to these lines within 
> {{org.apache.logging.log4j.core.Logger$PrivateConfig}} internal class:
> {code:java}
>         boolean filter(final Level level, final Marker marker, final String 
> msg) {
>             final Filter filter = config.getFilter();
>             if (filter != null) {
>                 final Filter.Result r = filter.filter(logger, level, marker, 
> msg);
>                 if (r != Filter.Result.NEUTRAL) {
>                     return r == Filter.Result.ACCEPT;
>                 }
>             }
>             return level != null && intLevel >= level.intLevel();
>         }
> {code}
> The first line is retrieving the filter from the global configuration 
> {{config.getFilter()}} instead of this logger's filter (if any) 
> {{loggerConfig.getFilter()}}. The global configuration filter is applied, 
> while the latter is simply ignored.
> Some additional notes follow:
>  * The same reasoning applies at least to the other {{filter(...)}} methods 
> in the PrivateConfig class.
>  * According to the documentation, the {{LoggerConfiguration}}'s level is 
> applied before the filters; but the code above doesn't say exactly the same 
> (if the filter result is {{ACCEPT}}, then the event is not filtered, 
> regardless the {{LoggerConfiguration}}'s level.
>  * This is in practice a duplicate of LOG4J2-1965. I don't know why it was 
> closed by the author just after having opened it, nor how it has not been 
> fixed since then.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to