public abstract class AbstractPropertyFilter
extends org.apache.log4j.spi.Filter
Abstract log4j filter base class which can be extended for specific property based logging event filtering. This abstract class provides three base properties, name, value and onMatchOption.
This abstract filter base class compares the runtime property value with the specified property value
by invoking the abstract getProperty(LoggingEvent, String)
method. Therefore, derived classes can implement
the getProperty(LoggingEvent, String)
method to read runtime properties from any environments such as Log4j MDC,
JNDI resources, etc.
The 'name' property is for specifying a property name, and the 'value' property is for specifying a property value
to be compared with the real property value at runtime.
Finally, the 'onMatchOption' property is for specifying the behavior when the property is matched.
The 'onMatchOption' property can be set to either 'ACCEPT' (Filter.ACCEPT
) or 'DENY' (Filter.DENY
).
If the 'onMatchOption' is set to 'ACCEPT', then the logging even will be accepted when the runtime property value matches with the specified property value. In this case, the logging event will be rejected if the runtime property value doesn't match.
If the 'onMatchOption' is set to 'DENY', then the logging event will be rejected when the runtime property value matches with the specified property value. In this case, the logging event will be accepted when the runtime property value doesn't match.
Filter
Constructor and Description |
---|
AbstractPropertyFilter() |
Modifier and Type | Method and Description |
---|---|
int |
decide(org.apache.log4j.spi.LoggingEvent event) |
String |
getName()
The property name on which to filter.
|
int |
getOnMatch()
Returns the deciding option whether or not the log message should be logged if a match is found.
|
String |
getOnMatchOption()
Returns string representation of the option flag whether or not the log message should be logged if a match is found.
|
protected abstract String |
getProperty(org.apache.log4j.spi.LoggingEvent event,
String name)
Finds the property value by the name from the underlying environment.
|
String |
getValue()
Gets the value to match.
|
void |
setName(String name)
Sets the property name on which to filter.
|
void |
setOnMatch(int onMatch)
Sets the deciding option whether or not the log message should be logged.
|
void |
setOnMatchOption(String onMatchOption)
Sets string representation of the option flag whether or not the log message should be logged.
|
void |
setValue(String value)
Sets the value to match.
|
public int decide(org.apache.log4j.spi.LoggingEvent event)
decide
in class org.apache.log4j.spi.Filter
public String getName()
public void setName(String name)
name
- the property name on which to filterpublic String getValue()
public void setValue(String value)
value
- the value to match.public int getOnMatch()
Filter.ACCEPT
,
Filter.DENY
public void setOnMatch(int onMatch)
Filter.ACCEPT
or Filter.DENY
.onMatch
- Filter.ACCEPT
,
Filter.DENY
public String getOnMatchOption()
Filter.ACCEPT
,
Filter.DENY
public void setOnMatchOption(String onMatchOption)
onMatchOption
- Filter.ACCEPT
,
Filter.DENY
Copyright © 2012–2016 Hippo B.V. (http://www.onehippo.com). All rights reserved.