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
This filter returns the onMatch result if the message matches the regular expression.
The "useRawMsg" attribute can be used to indicate whether the regular expression should be applied to the result of
calling Message.getMessageFormat (true) or Message.getFormattedMessage() (false). The default is false.
-
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.ResultNested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate final Patternprivate final booleanFields inherited from class org.apache.logging.log4j.core.filter.AbstractFilter
onMatch, onMismatchFields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGERFields inherited from interface org.apache.logging.log4j.core.Filter
ELEMENT_TYPE, EMPTY_ARRAY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateRegexFilter(boolean raw, Pattern pattern, Filter.Result onMatch, Filter.Result onMismatch) -
Method Summary
Modifier and TypeMethodDescriptionstatic RegexFiltercreateFilter(String regex, String[] patternFlags, Boolean useRawMsg, Filter.Result match, Filter.Result mismatch) Creates a Filter that matches a regular expression.private Filter.ResultContext Filter method.Appender Filter method.Appender Filter method.Appender Filter method.private static inttoPatternFlags(String[] patternFlags) 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, hashCodeImplMethods 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
-
Field Details
-
DEFAULT_PATTERN_FLAGS
private static final int DEFAULT_PATTERN_FLAGS- See Also:
-
pattern
-
useRawMessage
private final boolean useRawMessage
-
-
Constructor Details
-
RegexFilter
-
-
Method Details
-
filter
public Filter.Result filter(Logger logger, Level level, Marker marker, String msg, Object... params) Description copied from class:AbstractFilterAppender Filter method. The default returns NEUTRAL.- Specified by:
filterin interfaceFilter- Overrides:
filterin 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:AbstractFilterAppender Filter method. The default returns NEUTRAL.- Specified by:
filterin interfaceFilter- Overrides:
filterin 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:AbstractFilterAppender Filter method. The default returns NEUTRAL.- Specified by:
filterin interfaceFilter- Overrides:
filterin 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:AbstractFilterContext Filter method. The default returns NEUTRAL.- Specified by:
filterin interfaceFilter- Overrides:
filterin classAbstractFilter- Parameters:
event- The LogEvent.- Returns:
- The Result of filtering.
-
filter
-
toString
- Overrides:
toStringin 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- If true, the raw message will be used, otherwise the formatted message will be used.match- The action to perform when a match occurs.mismatch- The action to perform when a mismatch occurs.- Returns:
- The RegexFilter.
- Throws:
IllegalAccessExceptionIllegalArgumentException
-
toPatternFlags
private static int toPatternFlags(String[] patternFlags) throws IllegalArgumentException, IllegalAccessException
-