org.apache.logging.log4j.core.filter
Class AbstractFilter

java.lang.Object
  extended by org.apache.logging.log4j.core.AbstractLifeCycle
      extended by org.apache.logging.log4j.core.filter.AbstractFilter
All Implemented Interfaces:
Serializable, Filter, LifeCycle
Direct Known Subclasses:
BurstFilter, DynamicThresholdFilter, MapFilter, MarkerFilter, RegexFilter, ThresholdFilter, TimeFilter

public abstract class AbstractFilter
extends AbstractLifeCycle
implements Filter

Users should extend this class to implement filters. Filters can be either context wide or attached to an appender. A filter may choose to support being called only from the context or only from an appender in which case it will only implement the required method(s). The rest will default to return NEUTRAL.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.Filter
Filter.Result
 
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State
 
Field Summary
protected  Filter.Result onMatch
          The onMatch Result.
protected  Filter.Result onMismatch
          The onMismatch Result.
 
Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
LOGGER
 
Fields inherited from interface org.apache.logging.log4j.core.Filter
ELEMENT_TYPE
 
Constructor Summary
protected AbstractFilter()
          The default constructor.
protected AbstractFilter(Filter.Result onMatch, Filter.Result onMismatch)
          Constructor that allows the onMatch and onMismatch actions to be set.
 
Method Summary
protected  boolean equalsImpl(Object obj)
           
 Filter.Result filter(LogEvent event)
          Context Filter method.
 Filter.Result filter(Logger logger, org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, org.apache.logging.log4j.message.Message msg, Throwable t)
          Appender Filter method.
 Filter.Result filter(Logger logger, org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, Object msg, Throwable t)
          Appender Filter method.
 Filter.Result filter(Logger logger, org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, String msg, Object... params)
          Appender Filter method.
 Filter.Result getOnMatch()
          Returns the Result to be returned when a match occurs.
 Filter.Result getOnMismatch()
          Returns the Result to be returned when a match does not occur.
protected  int hashCodeImpl()
           
 String toString()
           
 
Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
getState, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.logging.log4j.core.LifeCycle
getState, isStarted, isStopped, start, stop
 

Field Detail

onMatch

protected final Filter.Result onMatch
The onMatch Result.


onMismatch

protected final Filter.Result onMismatch
The onMismatch Result.

Constructor Detail

AbstractFilter

protected AbstractFilter()
The default constructor.


AbstractFilter

protected AbstractFilter(Filter.Result onMatch,
                         Filter.Result onMismatch)
Constructor that allows the onMatch and onMismatch actions to be set.

Parameters:
onMatch - The result to return when a match occurs.
onMismatch - The result to return when a match dos not occur.
Method Detail

equalsImpl

protected boolean equalsImpl(Object obj)
Overrides:
equalsImpl in class AbstractLifeCycle

filter

public Filter.Result filter(LogEvent event)
Context Filter method. The default returns NEUTRAL.

Specified by:
filter in interface Filter
Parameters:
event - The LogEvent.
Returns:
The Result of filtering.

filter

public Filter.Result filter(Logger logger,
                            org.apache.logging.log4j.Level level,
                            org.apache.logging.log4j.Marker marker,
                            org.apache.logging.log4j.message.Message msg,
                            Throwable t)
Appender Filter method. The default returns NEUTRAL.

Specified by:
filter in interface Filter
Parameters:
logger - the Logger.
level - The logging Level.
marker - The Marker, if any.
msg - The message, if present.
t - A throwable or null.
Returns:
The Result of filtering.

filter

public Filter.Result filter(Logger logger,
                            org.apache.logging.log4j.Level level,
                            org.apache.logging.log4j.Marker marker,
                            Object msg,
                            Throwable t)
Appender Filter method. The default returns NEUTRAL.

Specified by:
filter in interface Filter
Parameters:
logger - the Logger.
level - The logging Level.
marker - The Marker, if any.
msg - The message, if present.
t - A throwable or null.
Returns:
The Result of filtering.

filter

public Filter.Result filter(Logger logger,
                            org.apache.logging.log4j.Level level,
                            org.apache.logging.log4j.Marker marker,
                            String msg,
                            Object... params)
Appender Filter method. The default returns NEUTRAL.

Specified by:
filter in interface Filter
Parameters:
logger - the Logger.
level - The logging Level.
marker - The Marker, if any.
msg - The message, if present.
params - An array of parameters or null.
Returns:
The Result of filtering.

getOnMatch

public final Filter.Result getOnMatch()
Returns the Result to be returned when a match occurs.

Specified by:
getOnMatch in interface Filter
Returns:
the onMatch Result.

getOnMismatch

public final Filter.Result getOnMismatch()
Returns the Result to be returned when a match does not occur.

Specified by:
getOnMismatch in interface Filter
Returns:
the onMismatch Result.

hashCodeImpl

protected int hashCodeImpl()
Overrides:
hashCodeImpl in class AbstractLifeCycle

toString

public String toString()
Overrides:
toString in class Object


Copyright © 1999-2015 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.