public class MDCMatchFilter extends MatchFilterBase
The filter admits three options KeyToMatch, ValueToMatch, and ExactMatch.
The value of KeyToMatch property determines which key is used to match against in the MDC. The value of that key is used to test against the ValueToMatchKeyToMatch property must be set before this filter can function properly.
The value of ValueToMatch property determines the
string value to match against. If ExactMatch is set
to true, a match will occur only when ValueToMatch exactly
matches the MDC value of the logging event. Otherwise, if the
ExactMatch property is set to false
, a match
will occur if ValueToMatch is contained anywhere within the
MDC value. The ExactMatch property is set to
false
by default.
Note that by default the value to match is set to
null
and will only match if the key is not contained
or the value is null in the MDC.
For more information about how the logging event will be
passed to the appender for reporting, please see
the MatchFilterBase
class.
ACCEPT_ON_MATCH, ACCEPT_ON_NOMATCH, DENY_ON_MATCH, DENY_ON_NOMATCH, matchReturnValue, noMatchReturnValue, UNKNOWN_POLICY
Constructor and Description |
---|
MDCMatchFilter() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
canMatch()
Returns true if a key to match has been configured.
|
boolean |
getExactMatch()
Returns the true if an exact match will be checked for.
|
String |
getKeyToMatch()
Gets the key to match in the MDC of the LoggingEvent.
|
String |
getValueToMatch()
Gets the value to match in the NDC value of the LoggingEvent.
|
protected boolean |
match(org.apache.log4j.spi.LoggingEvent event)
If ExactMatch is set to true, returns true only when
ValueToMatch exactly matches the MDC value of the
logging event.
|
void |
setExactMatch(boolean exact)
Set to true if configured value must exactly match the MDC
value of the LoggingEvent.
|
void |
setKeyToMatch(String key)
Sets the key to match in the MDC of the LoggingEvent.
|
void |
setValueToMatch(String value)
Sets the value to match in the NDC value of the LoggingEvent.
|
decide, getChainPolicy, getMatchReturnValue, getNoMatchReturnValue, setChainPolicy, setMatchReturnValue, setNoMatchReturnValue
public void setKeyToMatch(String key)
key
- The key that will be matched.public String getKeyToMatch()
public void setValueToMatch(String value)
value
- The value to match.public String getValueToMatch()
public void setExactMatch(boolean exact)
exact
- True if an exact match should be checked for.public boolean getExactMatch()
protected boolean canMatch()
canMatch
in class MatchFilterBase
protected boolean match(org.apache.log4j.spi.LoggingEvent event)
false
, returns true when
ValueToMatch is contained anywhere within the MDC
value. Otherwise, false is returned.match
in class MatchFilterBase
event
- The logging event to match against.Copyright © 2006–2020 OPS4J - Open Participation Software for Java. All rights reserved.