Skip to content

Commit 5377ee2

Browse files
committed
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.
1 parent 6c31f1b commit 5377ee2

File tree

7 files changed

+12
-121
lines changed

7 files changed

+12
-121
lines changed

log4j-parent/pom.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@
150150
<pax-exam.version>4.13.5</pax-exam.version>
151151
<plexus-utils.version>3.5.1</plexus-utils.version>
152152
<slf4j.version>2.0.9</slf4j.version>
153-
<!-- Last version before a breaking change -->
154-
<slf4j-ext.version>1.7.25</slf4j-ext.version>
155153
<system-stubs.version>2.1.5</system-stubs.version>
156154
<tomcat-juli.version>10.1.16</tomcat-juli.version>
157155
<velocity.version>1.7</velocity.version>
@@ -815,7 +813,7 @@
815813
<dependency>
816814
<groupId>org.slf4j</groupId>
817815
<artifactId>slf4j-ext</artifactId>
818-
<version>${slf4j-ext.version}</version>
816+
<version>${slf4j.version}</version>
819817
</dependency>
820818

821819
<dependency>

log4j-slf4j-impl/pom.xml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,7 @@
2929
<name>Apache Log4j SLF4J Binding</name>
3030
<description>The Apache Log4j SLF4J API binding to Log4j 2 Core</description>
3131
<properties>
32-
<log4jParentDir>${basedir}/..</log4jParentDir>
33-
<slf4j.version>1.7.25</slf4j.version>
34-
35-
<!--
36-
~ OSGi and JPMS options
37-
-->
38-
<bnd-extra-package-options>
39-
<!-- Optional dependencies -->
40-
org.slf4j.ext;resolution:=optional
41-
</bnd-extra-package-options>
42-
<bnd-extra-module-options>
43-
<!-- Optional module -->
44-
slf4j.ext;substitute="slf4j-ext";static=true;transitive=false,
45-
<!-- Version 1.7.25 has not module name, but 1.7.36 does -->
46-
org.slf4j;substitute="slf4j-api"
47-
</bnd-extra-module-options>
32+
<slf4j.version>1.7.36</slf4j.version>
4833
</properties>
4934
<dependencies>
5035
<dependency>
@@ -60,11 +45,6 @@
6045
<groupId>org.slf4j</groupId>
6146
<artifactId>slf4j-api</artifactId>
6247
</dependency>
63-
<dependency>
64-
<groupId>org.slf4j</groupId>
65-
<artifactId>slf4j-ext</artifactId>
66-
<optional>true</optional>
67-
</dependency>
6848
<dependency>
6949
<groupId>org.apache.logging.log4j</groupId>
7050
<artifactId>log4j-core</artifactId>
@@ -110,6 +90,11 @@
11090
<artifactId>junit-vintage-engine</artifactId>
11191
<scope>test</scope>
11292
</dependency>
93+
<dependency>
94+
<groupId>org.slf4j</groupId>
95+
<artifactId>slf4j-ext</artifactId>
96+
<scope>test</scope>
97+
</dependency>
11398
</dependencies>
11499
<build>
115100
<plugins>

log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/EventDataConverter.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jLogger.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
import org.apache.logging.log4j.message.ParameterizedMessage;
2222
import org.apache.logging.log4j.message.SimpleMessage;
2323
import org.apache.logging.log4j.spi.ExtendedLogger;
24-
import org.apache.logging.log4j.util.LoaderUtil;
2524
import org.slf4j.Marker;
26-
import org.slf4j.MarkerFactory;
2725
import org.slf4j.spi.LocationAwareLogger;
2826

2927
/**
@@ -33,18 +31,13 @@ public class Log4jLogger implements LocationAwareLogger {
3331

3432
public static final String FQCN = Log4jLogger.class.getName();
3533

36-
private static final Marker EVENT_MARKER = MarkerFactory.getMarker("EVENT");
37-
private static final EventDataConverter CONVERTER = createConverter();
38-
39-
private final boolean eventLogger;
4034
private final ExtendedLogger logger;
4135
private final String name;
4236
private final Log4jMarkerFactory markerFactory;
4337

4438
public Log4jLogger(final Log4jMarkerFactory markerFactory, final ExtendedLogger logger, final String name) {
4539
this.markerFactory = markerFactory;
4640
this.logger = logger;
47-
this.eventLogger = "EventLogger".equals(name);
4841
this.name = name;
4942
}
5043

@@ -364,10 +357,7 @@ public void log(
364357
}
365358
final Message msg;
366359
final Throwable actualThrowable;
367-
if (CONVERTER != null && eventLogger && marker != null && marker.contains(EVENT_MARKER)) {
368-
msg = CONVERTER.convertEvent(message, params, throwable);
369-
actualThrowable = throwable != null ? throwable : msg.getThrowable();
370-
} else if (params == null) {
360+
if (params == null) {
371361
msg = new SimpleMessage(message);
372362
actualThrowable = throwable;
373363
} else {
@@ -382,15 +372,6 @@ public String getName() {
382372
return name;
383373
}
384374

385-
private static EventDataConverter createConverter() {
386-
try {
387-
LoaderUtil.loadClass("org.slf4j.ext.EventData");
388-
return new EventDataConverter();
389-
} catch (final ClassNotFoundException cnfe) {
390-
return null;
391-
}
392-
}
393-
394375
private static Level getLevel(final int i) {
395376
switch (i) {
396377
case TRACE_INT:

log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerContextTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void testCleanup() throws Exception {
3434
final Log4jLoggerFactory factory = (Log4jLoggerFactory) LoggerFactory.getILoggerFactory();
3535
factory.getLogger("test");
3636
Set<LoggerContext> set = factory.getLoggerContexts();
37-
final LoggerContext ctx1 = set.toArray(new LoggerContext[0])[0];
37+
final LoggerContext ctx1 = set.toArray(LoggerContext.EMPTY_ARRAY)[0];
3838
assertTrue("LoggerContext is not enabled for shutdown", ctx1 instanceof LifeCycle);
3939
((LifeCycle) ctx1).stop();
4040
set = factory.getLoggerContexts();

log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static org.junit.Assert.assertTrue;
2222

2323
import java.util.List;
24-
import java.util.Locale;
2524
import org.apache.logging.log4j.core.LogEvent;
2625
import org.apache.logging.log4j.core.test.appender.ListAppender;
2726
import org.apache.logging.log4j.core.test.junit.LoggerContextRule;
@@ -34,8 +33,6 @@
3433
import org.slf4j.LoggerFactory;
3534
import org.slf4j.MDC;
3635
import org.slf4j.Marker;
37-
import org.slf4j.ext.EventData;
38-
import org.slf4j.ext.EventLogger;
3936
import org.slf4j.ext.XLogger;
4037
import org.slf4j.ext.XLoggerFactory;
4138
import org.slf4j.spi.LocationAwareLogger;
@@ -140,30 +137,12 @@ public void testRootLogger() {
140137
public void doubleSubst() {
141138
logger.debug("Hello, {}", "Log4j {}");
142139
verify("List", "o.a.l.s.LoggerTest Hello, Log4j {} MDC{}" + Strings.LINE_SEPARATOR);
140+
// XLogger 1.7.x performs substitution twice:
141+
// https://jira.qos.ch/browse/SLF4J-421
143142
xlogger.debug("Hello, {}", "Log4j {}");
144143
verify("List", "o.a.l.s.LoggerTest Hello, Log4j Log4j {} MDC{}" + Strings.LINE_SEPARATOR);
145144
}
146145

147-
@Test
148-
public void testEventLogger() {
149-
MDC.put("loginId", "JohnDoe");
150-
MDC.put("ipAddress", "192.168.0.120");
151-
MDC.put("locale", Locale.US.getDisplayName());
152-
final EventData data = new EventData();
153-
data.setEventType("Transfer");
154-
data.setEventId("Audit@18060");
155-
data.setMessage("Transfer Complete");
156-
data.put("ToAccount", "123456");
157-
data.put("FromAccount", "123457");
158-
data.put("Amount", "200.00");
159-
EventLogger.logEvent(data);
160-
MDC.clear();
161-
verify(
162-
"EventLogger",
163-
"o.a.l.s.LoggerTest Transfer [Audit@18060 Amount=\"200.00\" FromAccount=\"123457\" ToAccount=\"123456\"] Transfer Complete"
164-
+ Strings.LINE_SEPARATOR);
165-
}
166-
167146
@Test
168147
public void testThrowable() {
169148
final Throwable expected = new RuntimeException();
@@ -228,6 +207,5 @@ public void cleanup() {
228207
MDC.clear();
229208
ctx.getListAppender("List").clear();
230209
ctx.getListAppender("UnformattedList").clear();
231-
ctx.getListAppender("EventLogger").clear();
232210
}
233211
}

log4j-slf4j2-impl/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<version>${revision}</version>
2424
<relativePath>../log4j-parent</relativePath>
2525
</parent>
26+
2627
<artifactId>log4j-slf4j2-impl</artifactId>
2728
<packaging>jar</packaging>
2829
<name>Apache Log4j SLF4J 2.0 Binding</name>
@@ -105,7 +106,6 @@
105106
<dependency>
106107
<groupId>org.slf4j</groupId>
107108
<artifactId>slf4j-ext</artifactId>
108-
<version>${slf4j.version}</version>
109109
<scope>test</scope>
110110
</dependency>
111111
</dependencies>

0 commit comments

Comments
 (0)