[
https://issues.apache.org/jira/browse/LOG4J2-1911?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16027294#comment-16027294
]
Ralph Goers edited comment on LOG4J2-1911 at 5/27/17 6:37 AM:
--------------------------------------------------------------
I was able to add a test case that shows the problem and implemented a fix but
after thinking about the implications of the fix for the following reasons I
think the right thing to do is modify the documentation:
1. This filter has always worked this way. User's configurations would start
behaving differently if they upgrade.
2. Currently it only compares against the default threshold if the key and
value are present but no level is configured to check for that value. This
change would have it also compare against the default threshold if the key is
not present or the value is null, thus having the default threshold be applied
for two different situations.
3. If a key is not present in a log event this filter will currently return
NEUTRAL, passing the event on for further filtering. With this change, if
neither onMisMatch or onMatch are NEUTRAL then no further filtering can occur.
These are significant changes in behavior. Therefore I recommend that the the
documentation for defaultThreshold be modified to state that it only applies
when the log event has the specified ThreadContext item but no KeyValuePair has
been configured for that specific value, in which case the log event's level
will be compared against the default threshold. The description of the filter
should also be improved to say the filter returns NEUTRAL if the specified item
is not present in the ThreadContext.
was (Author: [email protected]):
I was able to add a test case that shows the problem and implemented a fix but
after thinking about the implications of the fix for the following reasons I
think the right thing to do is modify the documentation:
1. This filter has always worked this way. Users configurations would start
behaving differently if they upgrade.
2. Currently it only compares against the default threshold if the key and
value are present but no level is configured to check for that value. This
change would have it also compare against the default threshold if the key is
not present or the value is null, thus having the default threshold be applied
for two different situations.
3. If a key is not present in a log event this filter will currently return
NEUTRAL, passing the event on for further filtering. With this change, if
neither onMisMatch or onMatch are NEUTRAL then no further filtering can occur.
These are significant changes in behavior. Therefore I recommend that the the
documentation for defaultThreshold be modified to state that it only applies
when the log event has the specified ThreadContext item but no KeyValuePair has
been configured for that specific value, in which case the log event's level
will be compared against the default threshold. The description of the filter
should also be improved to say the filter returns NEUTRAL if the specified item
is not present in the ThreadContext.
> DynamicThresholdFilter defaultThreshold is not used to compare against
> event's level when there's no matching key found.
> ------------------------------------------------------------------------------------------------------------------------
>
> Key: LOG4J2-1911
> URL: https://issues.apache.org/jira/browse/LOG4J2-1911
> Project: Log4j 2
> Issue Type: Bug
> Components: Filters
> Affects Versions: 2.8.2
> Reporter: Jerry Chin
> Priority: Minor
> Labels: documentation, patch
>
> The {{defaultThreshold}} property is not honored as documented :
> {quote}
> defaultThreshold Level of messages to be filtered. If there is no
> matching key in the key/value pairs then this level will be compared against
> the event's level.
> {quote}
> after carefully examining the source code, I found the following code is
> called:
> {code:title=DynamicThresholdFilter.java|borderStyle=solid}
> private Result filter(Level level, ReadOnlyStringMap contextMap) {
> String value = (String)contextMap.getValue(this.key);
> if(value != null) {
> Level ctxLevel = (Level)this.levelMap.get(value);
> if(ctxLevel == null) {
> ctxLevel = this.defaultThreshold;
> }
> return
> level.isMoreSpecificThan(ctxLevel)?this.onMatch:this.onMismatch;
> } else {
> return Result.NEUTRAL;
> }
> }
> {code}
> where level is the event's level, when there's no matching key found
> {{contextMap}}, {{Result.NEUTRAL}} is mistakenly returned, instead of against
> {{this.defaultThreshold}}.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)