Description
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
Type
Projects
Status
Relationships
Development
- Removed @PluginAttribute 'patternFlags' argument from @PluginFactory for RegexFilter. (#3086)apache/logging-log4j2
- Removed @PluginAttribute 'patternFlags' argument from @PluginFactory for RegexFilter. (#3086)apache/logging-log4j2
- Updated RegexFilter implementtation with changes from 2.x branch merge to main [3.x] (#3086) apache/logging-log4j2
Activity
[-]Log4j 2.x Documentation - RegexFilter does not document the possible nested element PatternFlags [/-][+]Fix `RegexFilter` pattern flags[/+]ppkarwasz commentedon Oct 17, 2024
Hi @JWT007,
Thank you for helping us checking our documentation against the automatically-generated plugin reference. We created the plugin reference exactly for this purpose and we are happy you find it useful.
This is a longstanding LOG4J2-696 bug, old as Log4j 2 itself. The attempted solution has no chance to work, since the
@PluginElement
annotation only accepts classes annotated with@Plugin
andString
is final.Since you can embed pattern flags in the regex (e.g.
(?i)
instead ofCASE_SENSITIVE
), I believe that we can just remove the annotation on the parameter.Removed 'patternFlags' @PluginAttribute from RegexFilter @pluginfactory…
JWT007 commentedon Feb 12, 2025
@ppkarwasz - added another new PR.
Please review if OK how I deprecated old pluginFactory and created new one.
Updates per PR Code Review (apache#3086)
A few more improvements + added tests (apache#3086)
Removed 'patternFlags' @PluginAttribute from RegexFilter @pluginfactory…
Updates per PR Code Review (apache#3086)
A few more improvements + added tests (apache#3086)
Fix validation behavior in RegexFilter (apache#3086)
32 remaining items