Skip to content

Commit

Permalink
Remove slf4j-ext dependency and tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ppkarwasz committed Dec 28, 2023
1 parent a5b64a4 commit 0bfbc15
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 128 deletions.
6 changes: 0 additions & 6 deletions log4j-core-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +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>

<!-- Dependency versions -->
<slf4j-ext.version>${slf4j.version}</slf4j-ext.version>

<!--
~ OSGi and JPMS options
-->
Expand Down
6 changes: 0 additions & 6 deletions log4j-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -810,12 +810,6 @@
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-ext</artifactId>
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>uk.org.webcompere</groupId>
<artifactId>system-stubs-core</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions log4j-slf4j-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

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;
Expand All @@ -33,8 +32,6 @@
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;

/**
Expand All @@ -48,72 +45,39 @@ 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
public void mdc() {

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);
}

/**
Expand All @@ -123,7 +87,7 @@ public void mdc() {
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
Expand All @@ -136,11 +100,7 @@ public void testRootLogger() {
@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
Expand Down Expand Up @@ -183,10 +143,10 @@ private ListAppender getAppenderByName(final String name) {
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();
Expand Down
5 changes: 0 additions & 5 deletions log4j-slf4j2-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
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;
Expand All @@ -36,8 +35,6 @@
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;

Expand All @@ -52,88 +49,55 @@ 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
public void mdc() {

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);
}

/**
Expand All @@ -143,7 +107,7 @@ public void mdcStack() {
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
Expand All @@ -156,9 +120,7 @@ public void testRootLogger() {
@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
Expand Down Expand Up @@ -216,10 +178,10 @@ private ListAppender getAppenderByName(final String name) {
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();
Expand Down

0 comments on commit 0bfbc15

Please sign in to comment.