You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by pk...@apache.org on 2022/04/13 14:51:27 UTC

[logging-log4j2] branch release-2.x updated (fb83682941 -> ebfc8945a5)

This is an automated email from the ASF dual-hosted git repository.

pkarwasz pushed a change to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


    from fb83682941 Bump GitHub setup-java action to v3. (#816)
     new 5be42b2cfe [LOG4J2-3475] Add missing message parameterization in RegexFilter
     new ebfc8945a5 Add changelog entry for LOG4J2-3475

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../logging/log4j/core/filter/RegexFilter.java       |  6 +++++-
 .../logging/log4j/core/filter/RegexFilterTest.java   | 20 ++++++++++++++++++++
 src/changes/changes.xml                              |  3 +++
 3 files changed, 28 insertions(+), 1 deletion(-)


[logging-log4j2] 01/02: [LOG4J2-3475] Add missing message parameterization in RegexFilter

Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pkarwasz pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 5be42b2cfeb5c1dde1ee5b4e7a0fb476083ad568
Author: Jeremy Lin <je...@gmail.com>
AuthorDate: Tue Apr 12 22:18:57 2022 -0700

    [LOG4J2-3475] Add missing message parameterization in RegexFilter
---
 .../logging/log4j/core/filter/RegexFilter.java       |  6 +++++-
 .../logging/log4j/core/filter/RegexFilterTest.java   | 20 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java
index eafaef1f39..da8f20c563 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java
@@ -33,6 +33,7 @@ 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.ParameterizedMessage;
 
 /**
  * This filter returns the onMatch result if the message matches the regular expression.
@@ -57,7 +58,10 @@ public final class RegexFilter extends AbstractFilter {
     @Override
     public Result filter(final Logger logger, final Level level, final Marker marker, final String msg,
             final Object... params) {
-        return filter(msg);
+        if (useRawMessage || params == null || params.length == 0) {
+            return filter(msg);
+        }
+        return filter(ParameterizedMessage.format(msg, params));
     }
 
     @Override
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/RegexFilterTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/RegexFilterTest.java
index 19dbed9c84..9b68263237 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/RegexFilterTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/filter/RegexFilterTest.java
@@ -81,4 +81,24 @@ public class RegexFilterTest {
         assertSame(Filter.Result.DENY, filter.filter(null, Level.DEBUG, null, (Message) null, (Throwable) null));
         assertSame(Filter.Result.DENY, filter.filter(null, Level.DEBUG, null, null, (Object[]) null));
     }
+
+    @Test
+    public void testParameterizedMsg() throws Exception {
+        final String msg = "params {} {}";
+        final Object[] params = { "foo", "bar" };
+
+        // match against raw message
+        final RegexFilter rawFilter = RegexFilter.createFilter("params \\{\\} \\{\\}", null,
+                                                               true, // useRawMsg
+                                                               Result.ACCEPT, Result.DENY);
+        final Result rawResult = rawFilter.filter(null, null, null, msg, params);
+        assertThat(rawResult, equalTo(Result.ACCEPT));
+
+        // match against formatted message
+        final RegexFilter fmtFilter = RegexFilter.createFilter("params foo bar", null,
+                                                               false, // useRawMsg
+                                                               Result.ACCEPT, Result.DENY);
+        final Result fmtResult = fmtFilter.filter(null, null, null, msg, params);
+        assertThat(fmtResult, equalTo(Result.ACCEPT));
+    }
 }


[logging-log4j2] 02/02: Add changelog entry for LOG4J2-3475

Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pkarwasz pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit ebfc8945a5dd77b617f4667647ed4b740323acc8
Author: Jeremy Lin <je...@gmail.com>
AuthorDate: Wed Apr 13 02:06:23 2022 -0700

    Add changelog entry for LOG4J2-3475
---
 src/changes/changes.xml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1a62af7af6..7f7fdc296f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -94,6 +94,9 @@
       <action issue="LOG4J2-3440" dev="pkarwasz" type="add">
         Add support for adding and retrieving appenders in Log4j 1.x bridge.
       </action>
+      <action issue="LOG4J2-3475" dev="jjlin" type="fix" due-to="Jeremy Lin">
+        Add missing message parameterization in RegexFilter.
+      </action>
       <!-- UPDATES -->
       <action issue="LOG4J2-3428" dev="ggregory" type="fix" due-to="LF-Lin">
         Update 3rd party dependencies for 2.17.3.