Skip to content

Fix RegexFilter pattern flags #3086

@JWT007

Description

@JWT007

In the Log4j 2.x documentation for the RegexFilter:

https://logging.apache.org/log4j/2.x/manual/filters.html#RegexFilter

The only two configuration attributes are "regex" and "useRawMsg" (and the common filter attributes onMatch/onMismatch).

In the RegExFilter @pluginfactory there is a nested element for a set of Strings which is not mentioned in the documentation:

@PluginFactory public static RegexFilter createFilter( // @formatter:off @PluginAttribute("regex") final String regex, @PluginElement("PatternFlags") final String[] patternFlags, @PluginAttribute("useRawMsg") final Boolean useRawMsg, @PluginAttribute("onMatch") final Result match, @PluginAttribute("onMismatch") final Result mismatch) // @formatter:on throws IllegalArgumentException, IllegalAccessException { 

If I understand correctly one can provide field names from the Pattern class here: (CASE_INSENSITIVE, COMMENTS, etc.).

The example in the Plugin Reference for the RegexFilter shows an example of nested strings but is not very clear with "a-String-implementation":

<RegexFilter onMatch="" onMismatch="" regex="" useRawMsg=""> <a-String-implementation/><!-- multiple occurrences allowed --> </RegexFilter> 

Is it?:

<RegExFilter ...> <PatternFlags>CASE_INSENTIVE</PatternFlags> <PatternFlags>COMMENTS</PatternFlags> </RegExFilter> 

A usage example would be helpful.

Maybe this API is not really "public"? In the log4j-core-test RegexFilter test it seems the RegexFilter is never tested with anything but a null value for the patternFlags.

Metadata

Metadata

Assignees

Labels

bugIncorrect, unexpected, or unintended behavior of existing codeconfigurationAffects the configuration system in a general wayjavaPull requests that update Java code

Type

No type

Projects

Status

To triage

Relationships

None yet

Development

No branches or pull requests

Issue actions