Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f0ec0b8
Removed 'patternFlags' @PluginAttribute from RegexFilter @PluginFacto…
jethomas-tsi Feb 12, 2025
8c0e3c6
Improve configuration error handling of HttpAppender (#3438)
Suvrat1629 Feb 16, 2025
dd7b6d3
Updates per PR Code Review (#3086)
jethomas-tsi Feb 17, 2025
29e472b
A few more improvements + added tests (#3086)
jethomas-tsi Feb 17, 2025
85c6c9b
Publish build scans to develocity.apache.org (#3396)
clayburn Feb 18, 2025
fef8af8
Fix null termination advice for SOA and JTL
vy Feb 18, 2025
55b799b
Bump org.apache.logging:logging-parent from 11.3.0 to 12.0.0 in /log4…
dependabot[bot] Feb 18, 2025
382ea9b
Run reproducibility check after each deployment
ppkarwasz Oct 17, 2024
3846632
Run integration tests after each deployment (#3105)
ppkarwasz Feb 18, 2025
2b9a15f
Fix revision to `2.25.0-SNAPSHOT`
ppkarwasz Feb 18, 2025
f203d86
Fix Nexus URL for snapshots
ppkarwasz Feb 18, 2025
bd4607c
Update `org.apache.cassandra:cassandra-all` to version `3.11.19` (#3440)
asf-rm Feb 18, 2025
92d6efb
Activate `bom` profile in `log4j-bom`
ppkarwasz Feb 19, 2025
2202b58
Add Nexus URL argument to `generate-email.sh` per `logging-parent` up…
vy Feb 19, 2025
c3fa946
Document `maven-compiler-plugin` override
vy Feb 19, 2025
ae77c09
Update `org.mongodb:bson` to version `5.3.1` (#3409)
asf-rm Feb 19, 2025
0891d6b
Fix formatting of `s` pattern (#3469)
ppkarwasz Feb 19, 2025
eefffd9
Update `co.elastic.clients:elasticsearch-java` to version `8.17.2` (#…
asf-rm Feb 19, 2025
71a03d7
Update `commons-codec:commons-codec` to version `1.18.0` (#3421)
asf-rm Feb 19, 2025
f98bff4
Bump commons-logging:commons-logging in /log4j-parent (#3445)
dependabot[bot] Feb 19, 2025
5aac7d6
Update `org.openrewrite.recipe:rewrite-logging-frameworks` to version…
asf-rm Feb 19, 2025
07590bc
Add `collectionName` and `databaseName` attributes to `MongoDbProvide…
vy Feb 20, 2025
14adc25
Add changelog entry (#3066)
vy Feb 21, 2025
9bc402e
Update `fast-xml-parser` to version `5.0.6` (#3487)
asf-rm Feb 24, 2025
bf6ef23
Update `org.junit:junit-bom` to version `5.12.0` (#3488)
asf-rm Feb 24, 2025
6f4fab9
Update `org.awaitility:awaitility` to version `4.3.0` (#3489)
asf-rm Feb 24, 2025
dde535f
Update `org.slf4j:slf4j-nop` to version `2.0.17` (#3496)
asf-rm Feb 26, 2025
56d14a4
Update `org.slf4j:slf4j-nop` to version `2.0.17` (#3490)
asf-rm Feb 26, 2025
ca14c95
Update `org.slf4j:slf4j-api` to version `2.0.17` (#3492)
asf-rm Feb 26, 2025
2d08264
Update `org.slf4j:slf4j-api` to version `2.0.17` (#3497)
asf-rm Feb 26, 2025
b7cccc1
Update `org.slf4j:slf4j-api` to version `2.0.17` (#3498)
asf-rm Feb 26, 2025
727c992
Update `org.slf4j:slf4j-api` to version `2.0.17` (#3499)
asf-rm Feb 26, 2025
d8cbe77
Bugfix/log4 j 3359 2 (#3502)
JWT007 Feb 27, 2025
1da1d7e
Update `org.apache.groovy:groovy-bom` to version `4.0.26` (#3506)
asf-rm Feb 28, 2025
8d05a73
Fixed AbstractFilterable#isFiltered javadoc (#3300) (#3456)
JWT007 Mar 1, 2025
ffbdda5
Removed 'patternFlags' @PluginAttribute from RegexFilter @PluginFacto…
jethomas-tsi Feb 12, 2025
d5d7aed
Updates per PR Code Review (#3086)
jethomas-tsi Feb 17, 2025
6e7e82d
A few more improvements + added tests (#3086)
jethomas-tsi Feb 17, 2025
0ac7478
Merge remote-tracking branch 'jwt007/bugfix/LOG4J-3086' into bugfix/L…
JWT007 Mar 2, 2025
283dcff
Fix validation behavior in RegexFilter (#3086)
JWT007 Mar 2, 2025
6f1358c
Fixed a reverse logic check in a validation (#3086)
JWT007 Mar 2, 2025
c7f89d8
Fix Spotless errors (#3086)
JWT007 Mar 2, 2025
d6b5574
Fix RegexFilterTest (#3086)
JWT007 Mar 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
*/
package org.apache.logging.log4j.core.filter;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Comparator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.logging.log4j.Level;
Expand All @@ -29,7 +26,6 @@
import org.apache.logging.log4j.core.config.Node;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginElement;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.MessageFormatMessage;
Expand All @@ -43,7 +39,6 @@
@Plugin(name = "RegexFilter", category = Node.CATEGORY, elementType = Filter.ELEMENT_TYPE, printObject = true)
public final class RegexFilter extends AbstractFilter {

private static final int DEFAULT_PATTERN_FLAGS = 0;
private final Pattern pattern;
private final boolean useRawMessage;

Expand Down Expand Up @@ -110,10 +105,7 @@ private Result filter(final String msg) {

@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("useRaw=").append(useRawMessage);
sb.append(", pattern=").append(pattern.toString());
return sb.toString();
return "useRaw=" + useRawMessage + ", pattern=" + pattern.toString();
}

/**
Expand All @@ -123,6 +115,40 @@ public String toString() {
* The regular expression to match.
* @param patternFlags
* An array of Strings where each String is a {@link Pattern#compile(String, int)} compilation flag.
* (no longer used - pattern flags can be embedded in regex-expression.
* @param useRawMsg
* If {@code true}, for {@link ParameterizedMessage}, {@link StringFormattedMessage}, and {@link MessageFormatMessage}, the message format pattern; for {@link StructuredDataMessage}, the message field will be used as the match target.
* @param match
* The action to perform when a match occurs.
* @param mismatch
* The action to perform when a mismatch occurs.
* @return The RegexFilter.
* @throws IllegalAccessException When there is no access to the definition of the specified member.
* @throws IllegalArgumentException When passed an illegal or inappropriate argument.
* @deprecated use {@link #createFilter(String, Boolean, Result, Result)}
*/
@Deprecated
// TODO Consider refactoring to use AbstractFilter.AbstractFilterBuilder
public static RegexFilter createFilter(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whenever we need to modify a factory method, we usually create a Builder class instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ppkarwasz I significantly reworked this one - please review if OK

I reworked it so that all config parameters are accessible via getters (i.e. 'regex') - this sort of comes from my own prroblems with these classes where config parameters are not accessible later making it impossible to see how the element was configured (i.e. to recreate config at runtime). If this is OK I would probably make some new tickets to do the same for some other configuration items.

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

// LOG4J-3086 - pattern-flags can be embedded in RegEx expression

return createFilter(regex, useRawMsg, match, mismatch);
}

/**
* Creates a Filter that matches a regular expression.
*
* @param regex
* The regular expression to match.
* @param useRawMsg
* If {@code true}, for {@link ParameterizedMessage}, {@link StringFormattedMessage}, and {@link MessageFormatMessage}, the message format pattern; for {@link StructuredDataMessage}, the message field will be used as the match target.
* @param match
Expand All @@ -138,40 +164,23 @@ public String toString() {
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 {
boolean raw = Boolean.TRUE.equals(useRawMsg);
if (regex == null) {
LOGGER.error("A regular expression must be provided for RegexFilter");
return null;
}
return new RegexFilter(
Boolean.TRUE.equals(useRawMsg), Pattern.compile(regex, toPatternFlags(patternFlags)), match, mismatch);
}

private static int toPatternFlags(final String[] patternFlags)
throws IllegalArgumentException, IllegalAccessException {
if (patternFlags == null || patternFlags.length == 0) {
return DEFAULT_PATTERN_FLAGS;
}
final Field[] fields = Pattern.class.getDeclaredFields();
final Comparator<Field> comparator = (f1, f2) -> f1.getName().compareTo(f2.getName());
Arrays.sort(fields, comparator);
final String[] fieldNames = new String[fields.length];
for (int i = 0; i < fields.length; i++) {
fieldNames[i] = fields[i].getName();
}
int flags = DEFAULT_PATTERN_FLAGS;
for (final String test : patternFlags) {
final int index = Arrays.binarySearch(fieldNames, test);
if (index >= 0) {
final Field field = fields[index];
flags |= field.getInt(Pattern.class);
}
final Pattern pattern;
try {
pattern = Pattern.compile(regex);
} catch (final Exception ex) {
LOGGER.error("Unable to compile regular expression: {}", regex, ex);
return null;
}
return flags;
return new RegexFilter(raw, pattern, match, mismatch);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://logging.apache.org/xml/ns"
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
type="fixed">
<issue id="3086" link="https://github.com/apache/logging-log4j2/issues/3086"/>
<description format="asciidoc">
Removed 'patternFlags' @PluginAttribute from RegexFilter @PluginFactory createFilter.
</description>
</entry>