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 2023/12/28 10:42:21 UTC

(logging-log4j2) branch 2.x updated (d1914b21c8 -> b8cb35fbb8)

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

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


    from d1914b21c8 Update `com.fasterxml.jackson:jackson-bom` to version `2.16.1` (#2126)
     new 0809c8bea8 Removes support for `EventData`
     new 5f66d27f27 Remove `slf4j-ext` dependency and tests
     new 8db18ff7d4 Switch Javadoc into legacy mode
     new b8cb35fbb8 Add BND exception

The 4 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:
 log4j-core-test/pom.xml                            | 10 +--
 log4j-parent/pom.xml                               | 10 ---
 log4j-slf4j-impl/pom.xml                           | 10 +--
 .../apache/logging/slf4j/EventDataConverter.java   | 51 -------------
 .../java/org/apache/logging/slf4j/Log4jLogger.java | 20 +----
 .../org/apache/logging/slf4j/package-info.java     |  4 +-
 .../java/org/apache/logging/slf4j/LoggerTest.java  | 86 +++-------------------
 log4j-slf4j2-impl/pom.xml                          |  7 +-
 .../java/org/apache/logging/slf4j/LoggerTest.java  | 70 ++++--------------
 pom.xml                                            |  1 +
 10 files changed, 36 insertions(+), 233 deletions(-)
 delete mode 100644 log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/EventDataConverter.java


(logging-log4j2) 04/04: Add BND exception

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

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

commit b8cb35fbb88baccdbde36f157a5ef737f2d6ed22
Author: Piotr P. Karwasz <pi...@karwasz.org>
AuthorDate: Thu Dec 28 11:42:11 2023 +0100

    Add BND exception
---
 .../src/main/java/org/apache/logging/slf4j/package-info.java          | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/package-info.java b/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/package-info.java
index 511a8c77c3..13498a1040 100644
--- a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/package-info.java
+++ b/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/package-info.java
@@ -21,9 +21,11 @@
  */
 @Export
 @Header(name = Constants.BUNDLE_ACTIVATIONPOLICY, value = Constants.ACTIVATION_LAZY)
-@Version("2.21.0")
+@Version("2.23.0")
+@BaselineIgnore("2.23.0")
 package org.apache.logging.slf4j;
 
+import aQute.bnd.annotation.baseline.BaselineIgnore;
 import org.osgi.annotation.bundle.Export;
 import org.osgi.annotation.bundle.Header;
 import org.osgi.annotation.versioning.Version;


(logging-log4j2) 03/04: Switch Javadoc into legacy mode

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

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

commit 8db18ff7d424a6d72cb75a2e9e99423d9d27129f
Author: Piotr P. Karwasz <pi...@karwasz.org>
AuthorDate: Thu Dec 28 11:04:50 2023 +0100

    Switch Javadoc into legacy mode
---
 pom.xml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/pom.xml b/pom.xml
index 48b63d878d..d59d546fb7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -631,6 +631,7 @@
               <!-- `notimestamp` avoids `diff` noise and is required for reproducible builds: https://maven.apache.org/guides/mini/guide-reproducible-builds.html -->
               <notimestamp>true</notimestamp>
               <skip>${javadoc.skip}</skip>
+              <legacyMode>true</legacyMode>
               <bottom><![CDATA[<p align="center">
               Copyright &copy; {inceptionYear}-{currentYear} {organizationName}.
               All Rights Reserved.<br/>


(logging-log4j2) 02/04: Remove `slf4j-ext` dependency and tests

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

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

commit 5f66d27f2751869ed43eaab51c08b2b761f34584
Author: Piotr P. Karwasz <pi...@karwasz.org>
AuthorDate: Tue Dec 12 10:24:11 2023 +0100

    Remove `slf4j-ext` dependency and tests
    
    After the removal of `EventData`, the only usage of `slf4j-ext` was in
    tests.
    
    However, since all `slf4j-ext` method calls delegate to `slfj4-api`
    method calls there is no sense in testing it directly.
---
 log4j-core-test/pom.xml                            | 10 +---
 log4j-parent/pom.xml                               |  6 --
 log4j-slf4j-impl/pom.xml                           |  5 --
 .../java/org/apache/logging/slf4j/Log4jLogger.java |  2 -
 .../java/org/apache/logging/slf4j/LoggerTest.java  | 64 ++++----------------
 log4j-slf4j2-impl/pom.xml                          |  5 --
 .../java/org/apache/logging/slf4j/LoggerTest.java  | 70 +++++-----------------
 7 files changed, 29 insertions(+), 133 deletions(-)

diff --git a/log4j-core-test/pom.xml b/log4j-core-test/pom.xml
index 6b7d0382f9..4f02dff980 100644
--- a/log4j-core-test/pom.xml
+++ b/log4j-core-test/pom.xml
@@ -23,6 +23,7 @@
     <version>${revision}</version>
     <relativePath>../log4j-parent</relativePath>
   </parent>
+
   <artifactId>log4j-core-test</artifactId>
   <packaging>jar</packaging>
   <name>Apache Log4j Core Tests</name>
@@ -31,9 +32,6 @@
     <!-- Ignore less important (high rank) bugs for test artifacts -->
     <spotbugs.maxRank>9</spotbugs.maxRank>
 
-    <!-- Dependency versions -->
-    <slf4j-ext.version>${slf4j.version}</slf4j-ext.version>
-
     <!--
       ~ OSGi and JPMS options
       -->
@@ -322,12 +320,6 @@
       <artifactId>slf4j-api</artifactId>
       <scope>test</scope>
     </dependency>
-    <!-- SLF4J tests -->
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-ext</artifactId>
-      <scope>test</scope>
-    </dependency>
     <!-- Used for testing HttpAppender -->
     <dependency>
       <groupId>com.github.tomakehurst</groupId>
diff --git a/log4j-parent/pom.xml b/log4j-parent/pom.xml
index 9c16abbd19..78d8f92791 100644
--- a/log4j-parent/pom.xml
+++ b/log4j-parent/pom.xml
@@ -949,12 +949,6 @@
         <version>${slf4j.version}</version>
       </dependency>
 
-      <dependency>
-        <groupId>org.slf4j</groupId>
-        <artifactId>slf4j-ext</artifactId>
-        <version>${slf4j.version}</version>
-      </dependency>
-
       <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot</artifactId>
diff --git a/log4j-slf4j-impl/pom.xml b/log4j-slf4j-impl/pom.xml
index ca2ef503a6..7e7d067dc7 100644
--- a/log4j-slf4j-impl/pom.xml
+++ b/log4j-slf4j-impl/pom.xml
@@ -129,11 +129,6 @@
       <artifactId>junit-vintage-engine</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-ext</artifactId>
-      <scope>test</scope>
-    </dependency>
   </dependencies>
   <build>
     <plugins>
diff --git a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jLogger.java b/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jLogger.java
index a91cf972f5..2889a31d07 100644
--- a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jLogger.java
+++ b/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jLogger.java
@@ -26,9 +26,7 @@ import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.ParameterizedMessage;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.apache.logging.log4j.spi.ExtendedLogger;
-import org.apache.logging.log4j.util.LoaderUtil;
 import org.slf4j.Marker;
-import org.slf4j.MarkerFactory;
 import org.slf4j.spi.LocationAwareLogger;
 
 /**
diff --git a/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java b/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
index 031c41223e..c1fc9a7841 100644
--- a/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
+++ b/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
@@ -18,7 +18,6 @@ package org.apache.logging.slf4j;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 
 import java.util.List;
 import org.apache.logging.log4j.core.LogEvent;
@@ -33,8 +32,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
 import org.slf4j.Marker;
-import org.slf4j.ext.XLogger;
-import org.slf4j.ext.XLoggerFactory;
 import org.slf4j.spi.LocationAwareLogger;
 
 /**
@@ -48,61 +45,28 @@ public class LoggerTest {
     public static LoggerContextRule ctx = new LoggerContextRule(CONFIG);
 
     Logger logger = LoggerFactory.getLogger("LoggerTest");
-    XLogger xlogger = XLoggerFactory.getXLogger("LoggerTest");
-
-    @Test
-    public void basicFlow() {
-        xlogger.entry();
-        verify("List", "o.a.l.s.LoggerTest entry MDC{}" + Strings.LINE_SEPARATOR);
-        xlogger.exit();
-        verify("List", "o.a.l.s.LoggerTest exit MDC{}" + Strings.LINE_SEPARATOR);
-    }
-
-    @Test
-    public void simpleFlow() {
-        xlogger.entry(CONFIG);
-        verify("List", "o.a.l.s.LoggerTest entry with (log4j-test1.xml) MDC{}" + Strings.LINE_SEPARATOR);
-        xlogger.exit(0);
-        verify("List", "o.a.l.s.LoggerTest exit with (0) MDC{}" + Strings.LINE_SEPARATOR);
-    }
-
-    @Test
-    public void throwing() {
-        xlogger.throwing(new IllegalArgumentException("Test Exception"));
-        verify("List", "o.a.l.s.LoggerTest throwing MDC{}" + Strings.LINE_SEPARATOR);
-    }
-
-    @Test
-    public void catching() {
-        try {
-            throw new NullPointerException();
-        } catch (final Exception e) {
-            xlogger.catching(e);
-            verify("List", "o.a.l.s.LoggerTest catching MDC{}" + Strings.LINE_SEPARATOR);
-        }
-    }
 
     @Test
     public void debug() {
         logger.debug("Debug message");
-        verify("List", "o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
     }
 
     @Test
     public void debugNoParms() {
         logger.debug("Debug message {}");
-        verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
         logger.debug("Debug message {}", (Object[]) null);
-        verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
         ((LocationAwareLogger) logger)
                 .log(null, Log4jLogger.class.getName(), LocationAwareLogger.DEBUG_INT, "Debug message {}", null, null);
-        verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
     }
 
     @Test
     public void debugWithParms() {
         logger.debug("Hello, {}", "World");
-        verify("List", "o.a.l.s.LoggerTest Hello, World MDC{}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Hello, World MDC{}" + Strings.LINE_SEPARATOR);
     }
 
     @Test
@@ -110,10 +74,10 @@ public class LoggerTest {
 
         MDC.put("TestYear", "2010");
         logger.debug("Debug message");
-        verify("List", "o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Strings.LINE_SEPARATOR);
         MDC.clear();
         logger.debug("Debug message");
-        verify("List", "o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
     }
 
     /**
@@ -123,7 +87,7 @@ public class LoggerTest {
     public void supportsCustomSLF4JMarkers() {
         final Marker marker = new CustomFlatMarker("TEST");
         logger.debug(marker, "Test");
-        verify("List", "o.a.l.s.LoggerTest Test MDC{}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Test MDC{}" + Strings.LINE_SEPARATOR);
     }
 
     @Test
@@ -136,11 +100,7 @@ public class LoggerTest {
     @Test
     public void doubleSubst() {
         logger.debug("Hello, {}", "Log4j {}");
-        verify("List", "o.a.l.s.LoggerTest Hello, Log4j {} MDC{}" + Strings.LINE_SEPARATOR);
-        // XLogger 1.7.x performs substitution twice:
-        // https://jira.qos.ch/browse/SLF4J-421
-        xlogger.debug("Hello, {}", "Log4j {}");
-        verify("List", "o.a.l.s.LoggerTest Hello, Log4j Log4j {} MDC{}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Hello, Log4j {} MDC{}" + Strings.LINE_SEPARATOR);
     }
 
     @Test
@@ -183,10 +143,10 @@ public class LoggerTest {
         return listApp;
     }
 
-    private void verify(final String name, final String expected) {
-        final ListAppender listApp = getAppenderByName(name);
+    private void verify(final String expected) {
+        final ListAppender listApp = getAppenderByName("List");
         final List<String> events = listApp.getMessages();
-        assertTrue("Incorrect number of messages. Expected 1 Actual " + events.size(), events.size() == 1);
+        assertEquals("Incorrect number of messages. Expected 1 Actual " + events.size(), 1, events.size());
         final String actual = events.get(0);
         assertEquals("Incorrect message. Expected " + expected + ". Actual " + actual, expected, actual);
         listApp.clear();
diff --git a/log4j-slf4j2-impl/pom.xml b/log4j-slf4j2-impl/pom.xml
index a3a86fd1a0..5ff47bc745 100644
--- a/log4j-slf4j2-impl/pom.xml
+++ b/log4j-slf4j2-impl/pom.xml
@@ -103,11 +103,6 @@
       <artifactId>junit-vintage-engine</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-ext</artifactId>
-      <scope>test</scope>
-    </dependency>
   </dependencies>
   <build>
     <plugins>
diff --git a/log4j-slf4j2-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java b/log4j-slf4j2-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
index 2ca6d4c2d7..c5780437a2 100644
--- a/log4j-slf4j2-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
+++ b/log4j-slf4j2-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
@@ -19,7 +19,6 @@ package org.apache.logging.slf4j;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 
 import java.util.List;
 import org.apache.logging.log4j.Level;
@@ -36,8 +35,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
 import org.slf4j.Marker;
-import org.slf4j.ext.XLogger;
-import org.slf4j.ext.XLoggerFactory;
 import org.slf4j.spi.LocationAwareLogger;
 import org.slf4j.spi.LoggingEventBuilder;
 
@@ -52,61 +49,28 @@ public class LoggerTest {
     public static LoggerContextRule ctx = new LoggerContextRule(CONFIG);
 
     Logger logger = LoggerFactory.getLogger("LoggerTest");
-    XLogger xlogger = XLoggerFactory.getXLogger("LoggerTest");
-
-    @Test
-    public void basicFlow() {
-        xlogger.entry();
-        verify("List", "o.a.l.s.LoggerTest entry MDC{}" + Strings.LINE_SEPARATOR);
-        xlogger.exit();
-        verify("List", "o.a.l.s.LoggerTest exit MDC{}" + Strings.LINE_SEPARATOR);
-    }
-
-    @Test
-    public void simpleFlow() {
-        xlogger.entry(CONFIG);
-        verify("List", "o.a.l.s.LoggerTest entry with (log4j-test1.xml) MDC{}" + Strings.LINE_SEPARATOR);
-        xlogger.exit(0);
-        verify("List", "o.a.l.s.LoggerTest exit with (0) MDC{}" + Strings.LINE_SEPARATOR);
-    }
-
-    @Test
-    public void throwing() {
-        xlogger.throwing(new IllegalArgumentException("Test Exception"));
-        verify("List", "o.a.l.s.LoggerTest throwing MDC{}" + Strings.LINE_SEPARATOR);
-    }
-
-    @Test
-    public void catching() {
-        try {
-            throw new NullPointerException();
-        } catch (final Exception e) {
-            xlogger.catching(e);
-            verify("List", "o.a.l.s.LoggerTest catching MDC{}" + Strings.LINE_SEPARATOR);
-        }
-    }
 
     @Test
     public void debug() {
         logger.debug("Debug message");
-        verify("List", "o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
     }
 
     @Test
     public void debugNoParms() {
         logger.debug("Debug message {}");
-        verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
         logger.debug("Debug message {}", (Object[]) null);
-        verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
         ((LocationAwareLogger) logger)
                 .log(null, Log4jLogger.class.getName(), LocationAwareLogger.DEBUG_INT, "Debug message {}", null, null);
-        verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
     }
 
     @Test
     public void debugWithParms() {
         logger.debug("Hello, {}", "World");
-        verify("List", "o.a.l.s.LoggerTest Hello, World MDC{}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Hello, World MDC{}" + Strings.LINE_SEPARATOR);
     }
 
     @Test
@@ -114,26 +78,26 @@ public class LoggerTest {
 
         MDC.put("TestYear", "2010");
         logger.debug("Debug message");
-        verify("List", "o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Strings.LINE_SEPARATOR);
         MDC.clear();
         logger.debug("Debug message");
-        verify("List", "o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
     }
 
     @Test
     public void mdcStack() {
         MDC.pushByKey("TestYear", "2010");
         logger.debug("Debug message");
-        verify("List", "o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Strings.LINE_SEPARATOR);
         MDC.pushByKey("TestYear", "2011");
         logger.debug("Debug message");
-        verify("List", "o.a.l.s.LoggerTest Debug message MDC{TestYear=2011}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Debug message MDC{TestYear=2011}" + Strings.LINE_SEPARATOR);
         MDC.popByKey("TestYear");
         logger.debug("Debug message");
-        verify("List", "o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Strings.LINE_SEPARATOR);
         MDC.clear();
         logger.debug("Debug message");
-        verify("List", "o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
     }
 
     /**
@@ -143,7 +107,7 @@ public class LoggerTest {
     public void supportsCustomSLF4JMarkers() {
         final Marker marker = new CustomFlatMarker("TEST");
         logger.debug(marker, "Test");
-        verify("List", "o.a.l.s.LoggerTest Test MDC{}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Test MDC{}" + Strings.LINE_SEPARATOR);
     }
 
     @Test
@@ -156,9 +120,7 @@ public class LoggerTest {
     @Test
     public void doubleSubst() {
         logger.debug("Hello, {}", "Log4j {}");
-        verify("List", "o.a.l.s.LoggerTest Hello, Log4j {} MDC{}" + Strings.LINE_SEPARATOR);
-        xlogger.debug("Hello, {}", "Log4j {}");
-        verify("List", "o.a.l.s.LoggerTest Hello, Log4j {} MDC{}" + Strings.LINE_SEPARATOR);
+        verify("o.a.l.s.LoggerTest Hello, Log4j {} MDC{}" + Strings.LINE_SEPARATOR);
     }
 
     @Test
@@ -216,10 +178,10 @@ public class LoggerTest {
         return listApp;
     }
 
-    private void verify(final String name, final String expected) {
-        final ListAppender listApp = getAppenderByName(name);
+    private void verify(final String expected) {
+        final ListAppender listApp = getAppenderByName("List");
         final List<String> events = listApp.getMessages();
-        assertTrue("Incorrect number of messages. Expected 1 Actual " + events.size(), events.size() == 1);
+        assertEquals("Incorrect number of messages. Expected 1 Actual " + events.size(), 1, events.size());
         final String actual = events.get(0);
         assertEquals("Incorrect message. Expected " + expected + ". Actual " + actual, expected, actual);
         listApp.clear();


(logging-log4j2) 01/04: Removes support for `EventData`

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

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

commit 0809c8bea8b9c92859e21bb013eff72025fb6bd8
Author: Piotr P. Karwasz <pi...@karwasz.org>
AuthorDate: Fri Dec 8 10:55:08 2023 +0100

    Removes support for `EventData`
    
    The `org.slf4j.ext.EventData` class was a primitive equivalent of
    Log4j's `StructuredDataMessage`. QOS.CH published CVE-2018-8088 against
    this class and removed it from `slf4j-ext` version 1.7.26.
    
    For a long time we kept support code to convert `EventData` to its Log4j
    equivalent for compatibility's sake: users that relied on this class
    could still use Log4j Core, but the functionality was **automatically**
    disabled once they upgraded `slf4j-ext`.
    
    Since 5 years passed since `slfj4-ext` 1.7.26 was published, we can
    safely assume that all the users upgraded the library and the support
    code can be removed.
---
 log4j-parent/pom.xml                               |  6 +--
 log4j-slf4j-impl/pom.xml                           | 15 +++----
 .../apache/logging/slf4j/EventDataConverter.java   | 51 ----------------------
 .../java/org/apache/logging/slf4j/Log4jLogger.java | 18 +-------
 .../java/org/apache/logging/slf4j/LoggerTest.java  | 26 +----------
 log4j-slf4j2-impl/pom.xml                          |  2 +-
 6 files changed, 11 insertions(+), 107 deletions(-)

diff --git a/log4j-parent/pom.xml b/log4j-parent/pom.xml
index 75606164e4..9c16abbd19 100644
--- a/log4j-parent/pom.xml
+++ b/log4j-parent/pom.xml
@@ -16,9 +16,7 @@
   ~ limitations under the License.
   -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
   <modelVersion>4.0.0</modelVersion>
-
   <parent>
     <groupId>org.apache.logging.log4j</groupId>
     <artifactId>log4j-bom</artifactId>
@@ -140,8 +138,6 @@
     <pax-exam.version>4.13.5</pax-exam.version>
     <plexus-utils.version>3.5.1</plexus-utils.version>
     <slf4j.version>2.0.9</slf4j.version>
-    <!-- Last version before a breaking change -->
-    <slf4j-ext.version>1.7.25</slf4j-ext.version>
     <spring-boot.version>2.7.18</spring-boot.version>
     <spring-framework.version>5.3.31</spring-framework.version>
     <system-stubs.version>2.0.3</system-stubs.version>
@@ -956,7 +952,7 @@
       <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-ext</artifactId>
-        <version>${slf4j-ext.version}</version>
+        <version>${slf4j.version}</version>
       </dependency>
 
       <dependency>
diff --git a/log4j-slf4j-impl/pom.xml b/log4j-slf4j-impl/pom.xml
index 7fd0690ed2..ca2ef503a6 100644
--- a/log4j-slf4j-impl/pom.xml
+++ b/log4j-slf4j-impl/pom.xml
@@ -29,9 +29,6 @@
   <description>The Apache Log4j SLF4J API binding to Log4j 2 Core</description>
   <properties>
     <slf4j.version>1.7.36</slf4j.version>
-    <!-- Do not upgrade the SLF4J version. 1.7.26 broke backward compatibility. Users can update the version if
-      they do not require support for SLF4J's EventData -->
-    <slf4j-ext.version>1.7.25</slf4j-ext.version>
 
     <!--
       ~ OSGi and JPMS options
@@ -60,7 +57,7 @@
       <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-ext</artifactId>
-        <version>${slf4j-ext.version}</version>
+        <version>${slf4j.version}</version>
         <optional>true</optional>
       </dependency>
     </dependencies>
@@ -80,11 +77,6 @@
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-ext</artifactId>
-      <optional>true</optional>
-    </dependency>
     <dependency>
       <groupId>org.apache.logging.log4j</groupId>
       <artifactId>log4j-core</artifactId>
@@ -137,6 +129,11 @@
       <artifactId>junit-vintage-engine</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-ext</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   <build>
     <plugins>
diff --git a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/EventDataConverter.java b/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/EventDataConverter.java
deleted file mode 100644
index c1a0ea36c0..0000000000
--- a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/EventDataConverter.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.slf4j;
-
-import java.util.Map;
-import org.apache.logging.log4j.message.Message;
-import org.apache.logging.log4j.message.ParameterizedMessage;
-import org.apache.logging.log4j.message.StructuredDataMessage;
-import org.slf4j.ext.EventData;
-
-/**
- *
- */
-public class EventDataConverter {
-
-    public Message convertEvent(final String message, final Object[] objects, final Throwable throwable) {
-        try {
-            final EventData data = objects != null && objects[0] instanceof EventData
-                    ? (EventData) objects[0]
-                    : new EventData(message);
-            final StructuredDataMessage msg =
-                    new StructuredDataMessage(data.getEventId(), data.getMessage(), data.getEventType());
-            for (final Map.Entry<String, Object> entry : data.getEventMap().entrySet()) {
-                final String key = entry.getKey();
-                if (EventData.EVENT_TYPE.equals(key)
-                        || EventData.EVENT_ID.equals(key)
-                        || EventData.EVENT_MESSAGE.equals(key)) {
-                    continue;
-                }
-                msg.put(key, String.valueOf(entry.getValue()));
-            }
-            return msg;
-        } catch (final Exception ex) {
-            return new ParameterizedMessage(message, objects, throwable);
-        }
-    }
-}
diff --git a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jLogger.java b/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jLogger.java
index 7dd7fd565a..a91cf972f5 100644
--- a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jLogger.java
+++ b/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jLogger.java
@@ -39,10 +39,7 @@ public class Log4jLogger implements LocationAwareLogger, Serializable {
     public static final String FQCN = Log4jLogger.class.getName();
 
     private static final long serialVersionUID = 7869000638091304316L;
-    private static final Marker EVENT_MARKER = MarkerFactory.getMarker("EVENT");
-    private static final EventDataConverter CONVERTER = createConverter();
 
-    private final boolean eventLogger;
     private transient ExtendedLogger logger;
     private final String name;
     private transient Log4jMarkerFactory markerFactory;
@@ -50,7 +47,6 @@ public class Log4jLogger implements LocationAwareLogger, Serializable {
     public Log4jLogger(final Log4jMarkerFactory markerFactory, final ExtendedLogger logger, final String name) {
         this.markerFactory = markerFactory;
         this.logger = logger;
-        this.eventLogger = "EventLogger".equals(name);
         this.name = name;
     }
 
@@ -370,10 +366,7 @@ public class Log4jLogger implements LocationAwareLogger, Serializable {
         }
         final Message msg;
         final Throwable actualThrowable;
-        if (CONVERTER != null && eventLogger && marker != null && marker.contains(EVENT_MARKER)) {
-            msg = CONVERTER.convertEvent(message, params, throwable);
-            actualThrowable = throwable != null ? throwable : msg.getThrowable();
-        } else if (params == null) {
+        if (params == null) {
             msg = new SimpleMessage(message);
             actualThrowable = throwable;
         } else {
@@ -407,15 +400,6 @@ public class Log4jLogger implements LocationAwareLogger, Serializable {
         aOutputStream.defaultWriteObject();
     }
 
-    private static EventDataConverter createConverter() {
-        try {
-            LoaderUtil.loadClass("org.slf4j.ext.EventData");
-            return new EventDataConverter();
-        } catch (final ClassNotFoundException cnfe) {
-            return null;
-        }
-    }
-
     private static Level getLevel(final int i) {
         switch (i) {
             case TRACE_INT:
diff --git a/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java b/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
index e5b38a6a26..031c41223e 100644
--- a/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
+++ b/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
@@ -21,7 +21,6 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import java.util.List;
-import java.util.Locale;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.test.appender.ListAppender;
 import org.apache.logging.log4j.core.test.junit.LoggerContextRule;
@@ -34,8 +33,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
 import org.slf4j.Marker;
-import org.slf4j.ext.EventData;
-import org.slf4j.ext.EventLogger;
 import org.slf4j.ext.XLogger;
 import org.slf4j.ext.XLoggerFactory;
 import org.slf4j.spi.LocationAwareLogger;
@@ -140,30 +137,12 @@ public class LoggerTest {
     public void doubleSubst() {
         logger.debug("Hello, {}", "Log4j {}");
         verify("List", "o.a.l.s.LoggerTest Hello, Log4j {} MDC{}" + Strings.LINE_SEPARATOR);
+        // XLogger 1.7.x performs substitution twice:
+        // https://jira.qos.ch/browse/SLF4J-421
         xlogger.debug("Hello, {}", "Log4j {}");
         verify("List", "o.a.l.s.LoggerTest Hello, Log4j Log4j {} MDC{}" + Strings.LINE_SEPARATOR);
     }
 
-    @Test
-    public void testEventLogger() {
-        MDC.put("loginId", "JohnDoe");
-        MDC.put("ipAddress", "192.168.0.120");
-        MDC.put("locale", Locale.US.getDisplayName());
-        final EventData data = new EventData();
-        data.setEventType("Transfer");
-        data.setEventId("Audit@18060");
-        data.setMessage("Transfer Complete");
-        data.put("ToAccount", "123456");
-        data.put("FromAccount", "123457");
-        data.put("Amount", "200.00");
-        EventLogger.logEvent(data);
-        MDC.clear();
-        verify(
-                "EventLogger",
-                "o.a.l.s.LoggerTest Transfer [Audit@18060 Amount=\"200.00\" FromAccount=\"123457\" ToAccount=\"123456\"] Transfer Complete"
-                        + Strings.LINE_SEPARATOR);
-    }
-
     @Test
     public void testThrowable() {
         final Throwable expected = new RuntimeException();
@@ -228,6 +207,5 @@ public class LoggerTest {
         MDC.clear();
         ctx.getListAppender("List").clear();
         ctx.getListAppender("UnformattedList").clear();
-        ctx.getListAppender("EventLogger").clear();
     }
 }
diff --git a/log4j-slf4j2-impl/pom.xml b/log4j-slf4j2-impl/pom.xml
index 29a0e43e07..a3a86fd1a0 100644
--- a/log4j-slf4j2-impl/pom.xml
+++ b/log4j-slf4j2-impl/pom.xml
@@ -23,6 +23,7 @@
     <version>${revision}</version>
     <relativePath>../log4j-parent</relativePath>
   </parent>
+
   <artifactId>log4j-slf4j2-impl</artifactId>
   <packaging>jar</packaging>
   <name>Apache Log4j SLF4J 2.0 Binding</name>
@@ -105,7 +106,6 @@
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-ext</artifactId>
-      <version>${slf4j.version}</version>
       <scope>test</scope>
     </dependency>
   </dependencies>