Skip to content

Commit c422a70

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

File tree

6 files changed

+28
-128
lines changed

6 files changed

+28
-128
lines changed

log4j-core-test/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@
3232
<!-- Ignore less important (high rank) bugs for test artifacts -->
3333
<spotbugs.maxRank>9</spotbugs.maxRank>
3434

35-
<!-- Dependency versions -->
36-
<slf4j-ext.version>${slf4j.version}</slf4j-ext.version>
37-
38-
<!-- Dependency versions -->
39-
<slf4j-ext.version>${slf4j.version}</slf4j-ext.version>
40-
4135
<!--
4236
~ OSGi and JPMS options
4337
-->

log4j-parent/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -810,12 +810,6 @@
810810
<version>${slf4j.version}</version>
811811
</dependency>
812812

813-
<dependency>
814-
<groupId>org.slf4j</groupId>
815-
<artifactId>slf4j-ext</artifactId>
816-
<version>${slf4j.version}</version>
817-
</dependency>
818-
819813
<dependency>
820814
<groupId>uk.org.webcompere</groupId>
821815
<artifactId>system-stubs-core</artifactId>

log4j-slf4j-impl/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@
9090
<artifactId>junit-vintage-engine</artifactId>
9191
<scope>test</scope>
9292
</dependency>
93-
<dependency>
94-
<groupId>org.slf4j</groupId>
95-
<artifactId>slf4j-ext</artifactId>
96-
<scope>test</scope>
97-
</dependency>
9893
</dependencies>
9994
<build>
10095
<plugins>

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

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertNotNull;
21-
import static org.junit.Assert.assertTrue;
2221

2322
import java.util.List;
2423
import org.apache.logging.log4j.core.LogEvent;
@@ -33,8 +32,6 @@
3332
import org.slf4j.LoggerFactory;
3433
import org.slf4j.MDC;
3534
import org.slf4j.Marker;
36-
import org.slf4j.ext.XLogger;
37-
import org.slf4j.ext.XLoggerFactory;
3835
import org.slf4j.spi.LocationAwareLogger;
3936

4037
/**
@@ -48,72 +45,39 @@ public class LoggerTest {
4845
public static LoggerContextRule ctx = new LoggerContextRule(CONFIG);
4946

5047
Logger logger = LoggerFactory.getLogger("LoggerTest");
51-
XLogger xlogger = XLoggerFactory.getXLogger("LoggerTest");
52-
53-
@Test
54-
public void basicFlow() {
55-
xlogger.entry();
56-
verify("List", "o.a.l.s.LoggerTest entry MDC{}" + Strings.LINE_SEPARATOR);
57-
xlogger.exit();
58-
verify("List", "o.a.l.s.LoggerTest exit MDC{}" + Strings.LINE_SEPARATOR);
59-
}
60-
61-
@Test
62-
public void simpleFlow() {
63-
xlogger.entry(CONFIG);
64-
verify("List", "o.a.l.s.LoggerTest entry with (log4j-test1.xml) MDC{}" + Strings.LINE_SEPARATOR);
65-
xlogger.exit(0);
66-
verify("List", "o.a.l.s.LoggerTest exit with (0) MDC{}" + Strings.LINE_SEPARATOR);
67-
}
68-
69-
@Test
70-
public void throwing() {
71-
xlogger.throwing(new IllegalArgumentException("Test Exception"));
72-
verify("List", "o.a.l.s.LoggerTest throwing MDC{}" + Strings.LINE_SEPARATOR);
73-
}
74-
75-
@Test
76-
public void catching() {
77-
try {
78-
throw new NullPointerException();
79-
} catch (final Exception e) {
80-
xlogger.catching(e);
81-
verify("List", "o.a.l.s.LoggerTest catching MDC{}" + Strings.LINE_SEPARATOR);
82-
}
83-
}
8448

8549
@Test
8650
public void debug() {
8751
logger.debug("Debug message");
88-
verify("List", "o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
52+
verify("o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
8953
}
9054

9155
@Test
9256
public void debugNoParms() {
9357
logger.debug("Debug message {}");
94-
verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
58+
verify("o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
9559
logger.debug("Debug message {}", (Object[]) null);
96-
verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
60+
verify("o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
9761
((LocationAwareLogger) logger)
9862
.log(null, Log4jLogger.class.getName(), LocationAwareLogger.DEBUG_INT, "Debug message {}", null, null);
99-
verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
63+
verify("o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
10064
}
10165

10266
@Test
10367
public void debugWithParms() {
10468
logger.debug("Hello, {}", "World");
105-
verify("List", "o.a.l.s.LoggerTest Hello, World MDC{}" + Strings.LINE_SEPARATOR);
69+
verify("o.a.l.s.LoggerTest Hello, World MDC{}" + Strings.LINE_SEPARATOR);
10670
}
10771

10872
@Test
10973
public void mdc() {
11074

11175
MDC.put("TestYear", "2010");
11276
logger.debug("Debug message");
113-
verify("List", "o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Strings.LINE_SEPARATOR);
77+
verify("o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Strings.LINE_SEPARATOR);
11478
MDC.clear();
11579
logger.debug("Debug message");
116-
verify("List", "o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
80+
verify("o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
11781
}
11882

11983
/**
@@ -123,7 +87,7 @@ public void mdc() {
12387
public void supportsCustomSLF4JMarkers() {
12488
final Marker marker = new CustomFlatMarker("TEST");
12589
logger.debug(marker, "Test");
126-
verify("List", "o.a.l.s.LoggerTest Test MDC{}" + Strings.LINE_SEPARATOR);
90+
verify("o.a.l.s.LoggerTest Test MDC{}" + Strings.LINE_SEPARATOR);
12791
}
12892

12993
@Test
@@ -136,11 +100,7 @@ public void testRootLogger() {
136100
@Test
137101
public void doubleSubst() {
138102
logger.debug("Hello, {}", "Log4j {}");
139-
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
142-
xlogger.debug("Hello, {}", "Log4j {}");
143-
verify("List", "o.a.l.s.LoggerTest Hello, Log4j Log4j {} MDC{}" + Strings.LINE_SEPARATOR);
103+
verify("o.a.l.s.LoggerTest Hello, Log4j {} MDC{}" + Strings.LINE_SEPARATOR);
144104
}
145105

146106
@Test
@@ -183,10 +143,10 @@ private ListAppender getAppenderByName(final String name) {
183143
return listApp;
184144
}
185145

186-
private void verify(final String name, final String expected) {
187-
final ListAppender listApp = getAppenderByName(name);
146+
private void verify(final String expected) {
147+
final ListAppender listApp = getAppenderByName("List");
188148
final List<String> events = listApp.getMessages();
189-
assertTrue("Incorrect number of messages. Expected 1 Actual " + events.size(), events.size() == 1);
149+
assertEquals("Incorrect number of messages. Expected 1 Actual " + events.size(), 1, events.size());
190150
final String actual = events.get(0);
191151
assertEquals("Incorrect message. Expected " + expected + ". Actual " + actual, expected, actual);
192152
listApp.clear();

log4j-slf4j2-impl/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,6 @@
103103
<artifactId>junit-vintage-engine</artifactId>
104104
<scope>test</scope>
105105
</dependency>
106-
<dependency>
107-
<groupId>org.slf4j</groupId>
108-
<artifactId>slf4j-ext</artifactId>
109-
<scope>test</scope>
110-
</dependency>
111106
</dependencies>
112107
<build>
113108
<plugins>

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

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import static org.assertj.core.api.Assertions.assertThat;
2020
import static org.junit.Assert.assertEquals;
2121
import static org.junit.Assert.assertNotNull;
22-
import static org.junit.Assert.assertTrue;
2322

2423
import java.util.List;
2524
import org.apache.logging.log4j.Level;
@@ -36,8 +35,6 @@
3635
import org.slf4j.LoggerFactory;
3736
import org.slf4j.MDC;
3837
import org.slf4j.Marker;
39-
import org.slf4j.ext.XLogger;
40-
import org.slf4j.ext.XLoggerFactory;
4138
import org.slf4j.spi.LocationAwareLogger;
4239
import org.slf4j.spi.LoggingEventBuilder;
4340

@@ -52,88 +49,55 @@ public class LoggerTest {
5249
public static LoggerContextRule ctx = new LoggerContextRule(CONFIG);
5350

5451
Logger logger = LoggerFactory.getLogger("LoggerTest");
55-
XLogger xlogger = XLoggerFactory.getXLogger("LoggerTest");
56-
57-
@Test
58-
public void basicFlow() {
59-
xlogger.entry();
60-
verify("List", "o.a.l.s.LoggerTest entry MDC{}" + Strings.LINE_SEPARATOR);
61-
xlogger.exit();
62-
verify("List", "o.a.l.s.LoggerTest exit MDC{}" + Strings.LINE_SEPARATOR);
63-
}
64-
65-
@Test
66-
public void simpleFlow() {
67-
xlogger.entry(CONFIG);
68-
verify("List", "o.a.l.s.LoggerTest entry with (log4j-test1.xml) MDC{}" + Strings.LINE_SEPARATOR);
69-
xlogger.exit(0);
70-
verify("List", "o.a.l.s.LoggerTest exit with (0) MDC{}" + Strings.LINE_SEPARATOR);
71-
}
72-
73-
@Test
74-
public void throwing() {
75-
xlogger.throwing(new IllegalArgumentException("Test Exception"));
76-
verify("List", "o.a.l.s.LoggerTest throwing MDC{}" + Strings.LINE_SEPARATOR);
77-
}
78-
79-
@Test
80-
public void catching() {
81-
try {
82-
throw new NullPointerException();
83-
} catch (final Exception e) {
84-
xlogger.catching(e);
85-
verify("List", "o.a.l.s.LoggerTest catching MDC{}" + Strings.LINE_SEPARATOR);
86-
}
87-
}
8852

8953
@Test
9054
public void debug() {
9155
logger.debug("Debug message");
92-
verify("List", "o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
56+
verify("o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
9357
}
9458

9559
@Test
9660
public void debugNoParms() {
9761
logger.debug("Debug message {}");
98-
verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
62+
verify("o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
9963
logger.debug("Debug message {}", (Object[]) null);
100-
verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
64+
verify("o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
10165
((LocationAwareLogger) logger)
10266
.log(null, Log4jLogger.class.getName(), LocationAwareLogger.DEBUG_INT, "Debug message {}", null, null);
103-
verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
67+
verify("o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR);
10468
}
10569

10670
@Test
10771
public void debugWithParms() {
10872
logger.debug("Hello, {}", "World");
109-
verify("List", "o.a.l.s.LoggerTest Hello, World MDC{}" + Strings.LINE_SEPARATOR);
73+
verify("o.a.l.s.LoggerTest Hello, World MDC{}" + Strings.LINE_SEPARATOR);
11074
}
11175

11276
@Test
11377
public void mdc() {
11478

11579
MDC.put("TestYear", "2010");
11680
logger.debug("Debug message");
117-
verify("List", "o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Strings.LINE_SEPARATOR);
81+
verify("o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Strings.LINE_SEPARATOR);
11882
MDC.clear();
11983
logger.debug("Debug message");
120-
verify("List", "o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
84+
verify("o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
12185
}
12286

12387
@Test
12488
public void mdcStack() {
12589
MDC.pushByKey("TestYear", "2010");
12690
logger.debug("Debug message");
127-
verify("List", "o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Strings.LINE_SEPARATOR);
91+
verify("o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Strings.LINE_SEPARATOR);
12892
MDC.pushByKey("TestYear", "2011");
12993
logger.debug("Debug message");
130-
verify("List", "o.a.l.s.LoggerTest Debug message MDC{TestYear=2011}" + Strings.LINE_SEPARATOR);
94+
verify("o.a.l.s.LoggerTest Debug message MDC{TestYear=2011}" + Strings.LINE_SEPARATOR);
13195
MDC.popByKey("TestYear");
13296
logger.debug("Debug message");
133-
verify("List", "o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Strings.LINE_SEPARATOR);
97+
verify("o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Strings.LINE_SEPARATOR);
13498
MDC.clear();
13599
logger.debug("Debug message");
136-
verify("List", "o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
100+
verify("o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR);
137101
}
138102

139103
/**
@@ -143,7 +107,7 @@ public void mdcStack() {
143107
public void supportsCustomSLF4JMarkers() {
144108
final Marker marker = new CustomFlatMarker("TEST");
145109
logger.debug(marker, "Test");
146-
verify("List", "o.a.l.s.LoggerTest Test MDC{}" + Strings.LINE_SEPARATOR);
110+
verify("o.a.l.s.LoggerTest Test MDC{}" + Strings.LINE_SEPARATOR);
147111
}
148112

149113
@Test
@@ -156,9 +120,7 @@ public void testRootLogger() {
156120
@Test
157121
public void doubleSubst() {
158122
logger.debug("Hello, {}", "Log4j {}");
159-
verify("List", "o.a.l.s.LoggerTest Hello, Log4j {} MDC{}" + Strings.LINE_SEPARATOR);
160-
xlogger.debug("Hello, {}", "Log4j {}");
161-
verify("List", "o.a.l.s.LoggerTest Hello, Log4j {} MDC{}" + Strings.LINE_SEPARATOR);
123+
verify("o.a.l.s.LoggerTest Hello, Log4j {} MDC{}" + Strings.LINE_SEPARATOR);
162124
}
163125

164126
@Test
@@ -216,10 +178,10 @@ private ListAppender getAppenderByName(final String name) {
216178
return listApp;
217179
}
218180

219-
private void verify(final String name, final String expected) {
220-
final ListAppender listApp = getAppenderByName(name);
181+
private void verify(final String expected) {
182+
final ListAppender listApp = getAppenderByName("List");
221183
final List<String> events = listApp.getMessages();
222-
assertTrue("Incorrect number of messages. Expected 1 Actual " + events.size(), events.size() == 1);
184+
assertEquals("Incorrect number of messages. Expected 1 Actual " + events.size(), 1, events.size());
223185
final String actual = events.get(0);
224186
assertEquals("Incorrect message. Expected " + expected + ". Actual " + actual, expected, actual);
225187
listApp.clear();

0 commit comments

Comments
 (0)