Class RegexFilter
java.lang.Object
org.apache.logging.log4j.core.AbstractLifeCycle
org.apache.logging.log4j.core.filter.AbstractFilter
org.apache.logging.log4j.core.filter.RegexFilter
- All Implemented Interfaces:
Filter
,LifeCycle
,LifeCycle2
@Plugin(name="RegexFilter",
category="Core",
elementType="filter",
printObject=true)
public final class RegexFilter
extends AbstractFilter
A filter that matches the given regular expression pattern against messages.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.filter.AbstractFilter
AbstractFilter.AbstractFilterBuilder<B extends AbstractFilter.AbstractFilterBuilder<B>>
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
Fields inherited from class org.apache.logging.log4j.core.filter.AbstractFilter
onMatch, onMismatch
Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER
Fields inherited from interface org.apache.logging.log4j.core.Filter
ELEMENT_TYPE, EMPTY_ARRAY
-
Method Summary
Modifier and TypeMethodDescriptionstatic RegexFilter
createFilter
(String regex, String[] patternFlags, Boolean useRawMsg, Filter.Result match, Filter.Result mismatch) Creates a Filter that matches a regular expression.Context Filter method.Appender Filter method.Appender Filter method.Appender Filter method.toString()
Methods inherited from class org.apache.logging.log4j.core.filter.AbstractFilter
equalsImpl, filter, filter, filter, filter, filter, filter, filter, filter, filter, filter, getOnMatch, getOnMismatch, hashCodeImpl
Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
getState, getStatusLogger, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, start, stop, stop, stop
-
Method Details
-
filter
public Filter.Result filter(Logger logger, Level level, Marker marker, String msg, Object... params) Description copied from class:AbstractFilter
Appender Filter method. The default returns NEUTRAL.- Specified by:
filter
in interfaceFilter
- Overrides:
filter
in classAbstractFilter
- 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.
-
filter
Description copied from class:AbstractFilter
Appender Filter method. The default returns NEUTRAL.- Specified by:
filter
in interfaceFilter
- Overrides:
filter
in classAbstractFilter
- 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
Description copied from class:AbstractFilter
Appender Filter method. The default returns NEUTRAL.- Specified by:
filter
in interfaceFilter
- Overrides:
filter
in classAbstractFilter
- 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
Description copied from class:AbstractFilter
Context Filter method. The default returns NEUTRAL.- Specified by:
filter
in interfaceFilter
- Overrides:
filter
in classAbstractFilter
- Parameters:
event
- The LogEvent.- Returns:
- The Result of filtering.
-
toString
- Overrides:
toString
in classAbstractFilter
-
createFilter
@PluginFactory public static RegexFilter createFilter(@PluginAttribute("regex") String regex, @PluginElement("PatternFlags") String[] patternFlags, @PluginAttribute("useRawMsg") Boolean useRawMsg, @PluginAttribute("onMatch") Filter.Result match, @PluginAttribute("onMismatch") Filter.Result mismatch) throws IllegalArgumentException, IllegalAccessException Creates a Filter that matches a regular expression.- Parameters:
regex
- The regular expression to match.patternFlags
- An array of Strings where each String is aPattern.compile(String, int)
compilation flag.useRawMsg
- Iftrue
, forParameterizedMessage
,StringFormattedMessage
, andMessageFormatMessage
, the message format pattern; forStructuredDataMessage
, the message field will be used as the match target.match
- The action to perform when a match occurs.mismatch
- The action to perform when a mismatch occurs.- Returns:
- The RegexFilter.
- Throws:
IllegalAccessException
- When there is no access to the definition of the specified member.IllegalArgumentException
- When passed an illegal or inappropriate argument.
-