diff --git a/log4j-core-test/pom.xml b/log4j-core-test/pom.xml index bd3a339e2ab..2d9d45e6abf 100644 --- a/log4j-core-test/pom.xml +++ b/log4j-core-test/pom.xml @@ -32,12 +32,6 @@ 9 - - ${slf4j.version} - - - ${slf4j.version} - diff --git a/log4j-parent/pom.xml b/log4j-parent/pom.xml index f5c21dfa3af..1918af41b2c 100644 --- a/log4j-parent/pom.xml +++ b/log4j-parent/pom.xml @@ -150,8 +150,6 @@ 4.13.5 3.5.1 2.0.9 - - 1.7.25 2.1.5 10.1.17 1.7 @@ -812,12 +810,6 @@ ${slf4j.version} - - org.slf4j - slf4j-ext - ${slf4j-ext.version} - - uk.org.webcompere system-stubs-core diff --git a/log4j-slf4j-impl/pom.xml b/log4j-slf4j-impl/pom.xml index b62388ad3e4..2b973cf73d0 100644 --- a/log4j-slf4j-impl/pom.xml +++ b/log4j-slf4j-impl/pom.xml @@ -29,22 +29,7 @@ Apache Log4j SLF4J Binding The Apache Log4j SLF4J API binding to Log4j 2 Core - ${basedir}/.. - 1.7.25 - - - - - org.slf4j.ext;resolution:=optional - - - - slf4j.ext;substitute="slf4j-ext";static=true;transitive=false, - - org.slf4j;substitute="slf4j-api" - + 1.7.36 @@ -60,11 +45,6 @@ org.slf4j slf4j-api - - org.slf4j - slf4j-ext - true - org.apache.logging.log4j log4j-core 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 c1a0ea36c09..00000000000 --- 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 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 e6fd5212994..41848745051 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 @@ -21,9 +21,7 @@ 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; /** @@ -33,10 +31,6 @@ public class Log4jLogger implements LocationAwareLogger { public static final String FQCN = Log4jLogger.class.getName(); - private static final Marker EVENT_MARKER = MarkerFactory.getMarker("EVENT"); - private static final EventDataConverter CONVERTER = createConverter(); - - private final boolean eventLogger; private final ExtendedLogger logger; private final String name; private final Log4jMarkerFactory markerFactory; @@ -44,7 +38,6 @@ public class Log4jLogger implements LocationAwareLogger { 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; } @@ -364,10 +357,7 @@ public void log( } 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 { @@ -382,15 +372,6 @@ public String getName() { return name; } - 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/LoggerContextTest.java b/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerContextTest.java index 13c7da42c5a..d77e1d4d342 100644 --- a/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerContextTest.java +++ b/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerContextTest.java @@ -34,7 +34,7 @@ public void testCleanup() throws Exception { final Log4jLoggerFactory factory = (Log4jLoggerFactory) LoggerFactory.getILoggerFactory(); factory.getLogger("test"); Set set = factory.getLoggerContexts(); - final LoggerContext ctx1 = set.toArray(new LoggerContext[0])[0]; + final LoggerContext ctx1 = set.toArray(LoggerContext.EMPTY_ARRAY)[0]; assertTrue("LoggerContext is not enabled for shutdown", ctx1 instanceof LifeCycle); ((LifeCycle) ctx1).stop(); set = factory.getLoggerContexts(); 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 e5b38a6a26c..c1fc9a7841e 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,10 +18,8 @@ import static org.junit.Assert.assertEquals; 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,10 +32,6 @@ 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; /** @@ -51,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 @@ -113,10 +74,10 @@ 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); } /** @@ -126,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 @@ -139,29 +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.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); + verify("o.a.l.s.LoggerTest Hello, Log4j {} MDC{}" + Strings.LINE_SEPARATOR); } @Test @@ -204,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 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(); @@ -228,6 +167,5 @@ public void cleanup() { 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 568f9cf0058..9f4530cf3bd 100644 --- a/log4j-slf4j2-impl/pom.xml +++ b/log4j-slf4j2-impl/pom.xml @@ -23,6 +23,7 @@ ${revision} ../log4j-parent + log4j-slf4j2-impl jar Apache Log4j SLF4J 2.0 Binding @@ -102,12 +103,6 @@ junit-vintage-engine test - - org.slf4j - slf4j-ext - ${slf4j.version} - test - 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 2ca6d4c2d74..c5780437a2c 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 @@ 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.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 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); } /** @@ -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 @@ -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 @@ -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 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/pom.xml b/pom.xml index f00242ec986..52affcc90ce 100644 --- a/pom.xml +++ b/pom.xml @@ -668,6 +668,7 @@ true ${maven.javadoc.skip} + true Copyright © {inceptionYear}-{currentYear} {organizationName}. All Rights Reserved.