AAdd upstream patch for compatibility with the latest slf4j versions
Signed-off-by: Alexander Scheel <ascheel@redhat.com>
This commit is contained in:
parent
23218df48d
commit
d142937e0e
@ -2,7 +2,7 @@
|
||||
|
||||
Name: log4j
|
||||
Version: 2.13.0
|
||||
Release: 2%{?dist}
|
||||
Release: 3%{?dist}
|
||||
Summary: Java logging package
|
||||
BuildArch: noarch
|
||||
License: ASL 2.0
|
||||
@ -10,6 +10,9 @@ License: ASL 2.0
|
||||
URL: http://logging.apache.org/%{name}
|
||||
Source0: http://www.apache.org/dist/logging/%{name}/%{version}/apache-%{name}-%{version}-src.tar.gz
|
||||
|
||||
Patch1: logging-log4j-LOG4J2-2745-LOG4J2-2744-slf4j.patch
|
||||
Patch2: logging-log4j-Remove-unsupported-EventDataConverter.patch
|
||||
|
||||
BuildRequires: maven-local
|
||||
BuildRequires: mvn(com.fasterxml.jackson.core:jackson-annotations)
|
||||
BuildRequires: mvn(com.fasterxml.jackson.core:jackson-core)
|
||||
@ -133,6 +136,7 @@ Obsoletes: %{name}-manual < %{version}
|
||||
|
||||
%prep
|
||||
%setup -q -n apache-%{name}-%{version}-src
|
||||
%autopatch -p1
|
||||
|
||||
%pom_remove_plugin -r :maven-site-plugin
|
||||
%pom_remove_plugin -r :maven-remote-resources-plugin
|
||||
@ -276,6 +280,9 @@ rm -r log4j-1.2-api/src/main/java/org/apache/log4j/or/jms
|
||||
|
||||
|
||||
%changelog
|
||||
* Thu Jan 30 2020 Fabio Valentini <decathorpe@gmail.com> - 2.13.0-3
|
||||
- Add upstream patch for compatibility with the latest slf4j versions.
|
||||
|
||||
* Wed Jan 29 2020 Fedora Release Engineering <releng@fedoraproject.org> - 2.13.0-2
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild
|
||||
|
||||
|
||||
307
logging-log4j-LOG4J2-2745-LOG4J2-2744-slf4j.patch
Normal file
307
logging-log4j-LOG4J2-2745-LOG4J2-2744-slf4j.patch
Normal file
@ -0,0 +1,307 @@
|
||||
diff --git a/log4j-slf4j18-impl/pom.xml b/log4j-slf4j18-impl/pom.xml
|
||||
index 8332557..ea25131 100644
|
||||
--- a/log4j-slf4j18-impl/pom.xml
|
||||
+++ b/log4j-slf4j18-impl/pom.xml
|
||||
@@ -31,7 +31,7 @@
|
||||
<log4jParentDir>${basedir}/..</log4jParentDir>
|
||||
<docLabel>SLF4J Documentation</docLabel>
|
||||
<projectDir>/slf4j18</projectDir>
|
||||
- <slf4j.version>1.8.0-alpha2</slf4j.version>
|
||||
+ <slf4j.version>1.8.0-beta4</slf4j.version>
|
||||
<module.name>org.apache.logging.log4j.slf4j</module.name>
|
||||
</properties>
|
||||
<dependencies>
|
||||
diff --git a/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/EventDataConverter.java b/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/EventDataConverter.java
|
||||
deleted file mode 100644
|
||||
index 620232a..0000000
|
||||
--- a/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/EventDataConverter.java
|
||||
+++ /dev/null
|
||||
@@ -1,50 +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-slf4j18-impl/src/main/java/org/apache/logging/slf4j/Log4jLogger.java b/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/Log4jLogger.java
|
||||
index 6cbb7c4..10ad49c 100644
|
||||
--- a/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/Log4jLogger.java
|
||||
+++ b/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/Log4jLogger.java
|
||||
@@ -27,9 +27,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;
|
||||
|
||||
/**
|
||||
@@ -40,19 +38,14 @@ 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 final boolean eventLogger;
|
||||
private transient ExtendedLogger logger;
|
||||
private final String name;
|
||||
- private transient EventDataConverter converter;
|
||||
private transient Log4jMarkerFactory markerFactory;
|
||||
|
||||
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;
|
||||
- this.converter = createConverter();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -364,9 +357,7 @@ public class Log4jLogger implements LocationAwareLogger, Serializable {
|
||||
return;
|
||||
}
|
||||
final Message msg;
|
||||
- if (eventLogger && marker != null && marker.contains(EVENT_MARKER) && converter != null) {
|
||||
- msg = converter.convertEvent(message, params, throwable);
|
||||
- } else if (params == null) {
|
||||
+ if (params == null) {
|
||||
msg = new SimpleMessage(message);
|
||||
} else {
|
||||
msg = new ParameterizedMessage(message, params, throwable);
|
||||
@@ -400,7 +391,6 @@ public class Log4jLogger implements LocationAwareLogger, Serializable {
|
||||
// always perform the default de-serialization first
|
||||
aInputStream.defaultReadObject();
|
||||
logger = LogManager.getContext().getLogger(name);
|
||||
- converter = createConverter();
|
||||
markerFactory = ((Log4jLoggerFactory) org.slf4j.LoggerFactory.getILoggerFactory()).getMarkerFactory();
|
||||
}
|
||||
|
||||
@@ -412,15 +402,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-slf4j18-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
|
||||
index 0524074..c60f1ad 100644
|
||||
--- a/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
|
||||
+++ b/log4j-slf4j18-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.junit.LoggerContextRule;
|
||||
import org.apache.logging.log4j.test.appender.ListAppender;
|
||||
@@ -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;
|
||||
@@ -145,23 +142,6 @@ public class LoggerTest {
|
||||
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);
|
||||
- }
|
||||
-
|
||||
private void verify(final String name, final String expected) {
|
||||
final ListAppender listApp = ctx.getListAppender(name);
|
||||
assertNotNull("Missing Appender", listApp);
|
||||
@@ -177,6 +157,5 @@ public class LoggerTest {
|
||||
public void cleanup() {
|
||||
MDC.clear();
|
||||
ctx.getListAppender("List").clear();
|
||||
- ctx.getListAppender("EventLogger").clear();
|
||||
}
|
||||
}
|
||||
diff --git a/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/OptionalTest.java b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/OptionalTest.java
|
||||
deleted file mode 100644
|
||||
index a6e9fd5..0000000
|
||||
--- a/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/OptionalTest.java
|
||||
+++ /dev/null
|
||||
@@ -1,69 +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.List;
|
||||
-
|
||||
-import org.apache.logging.log4j.junit.LoggerContextRule;
|
||||
-import org.apache.logging.log4j.test.appender.ListAppender;
|
||||
-import org.apache.logging.log4j.util.Strings;
|
||||
-import org.junit.Before;
|
||||
-import org.junit.ClassRule;
|
||||
-import org.junit.Test;
|
||||
-import org.slf4j.Logger;
|
||||
-import org.slf4j.LoggerFactory;
|
||||
-import org.slf4j.MDC;
|
||||
-import org.slf4j.Marker;
|
||||
-import org.slf4j.MarkerFactory;
|
||||
-
|
||||
-import static org.junit.Assert.*;
|
||||
-
|
||||
-/**
|
||||
- *
|
||||
- */
|
||||
-public class OptionalTest {
|
||||
-
|
||||
- private static final String CONFIG = "log4j-test1.xml";
|
||||
-
|
||||
- @ClassRule
|
||||
- public static final LoggerContextRule CTX = new LoggerContextRule(CONFIG);
|
||||
-
|
||||
- Logger logger = LoggerFactory.getLogger("EventLogger");
|
||||
- Marker marker = MarkerFactory.getMarker("EVENT");
|
||||
-
|
||||
- @Test
|
||||
- public void testEventLogger() {
|
||||
- logger.info(marker, "This is a test");
|
||||
- MDC.clear();
|
||||
- verify("EventLogger", "o.a.l.s.OptionalTest This is a test" + Strings.LINE_SEPARATOR);
|
||||
- }
|
||||
-
|
||||
- private void verify(final String name, final String expected) {
|
||||
- final ListAppender listApp = CTX.getListAppender(name);
|
||||
- final List<String> events = listApp.getMessages();
|
||||
- assertTrue("Incorrect number of messages. Expected 1 Actual " + events.size(), events.size()== 1);
|
||||
- final String actual = events.get(0);
|
||||
- assertEquals("Incorrect message. Expected " + expected + ". Actual " + actual, expected, actual);
|
||||
- listApp.clear();
|
||||
- }
|
||||
-
|
||||
- @Before
|
||||
- public void cleanup() {
|
||||
- CTX.getListAppender("List").clear();
|
||||
- CTX.getListAppender("EventLogger").clear();
|
||||
- }
|
||||
-}
|
||||
diff --git a/log4j-slf4j18-impl/src/test/resources/log4j-test1.xml b/log4j-slf4j18-impl/src/test/resources/log4j-test1.xml
|
||||
index a64bdfa..07a2be6 100644
|
||||
--- a/log4j-slf4j18-impl/src/test/resources/log4j-test1.xml
|
||||
+++ b/log4j-slf4j18-impl/src/test/resources/log4j-test1.xml
|
||||
@@ -6,9 +6,6 @@
|
||||
<ThresholdFilter level="trace"/>
|
||||
|
||||
<Appenders>
|
||||
- <List name="EventLogger">
|
||||
- <PatternLayout pattern="%C{1.} %m%n"/>
|
||||
- </List>
|
||||
<Console name="STDOUT">
|
||||
<PatternLayout pattern="%C{1.} %m MDC%X%n"/>
|
||||
</Console>
|
||||
@@ -24,10 +21,6 @@
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
- <Logger name="EventLogger" level="info" additivity="false">
|
||||
- <AppenderRef ref="EventLogger"/>
|
||||
- </Logger>>
|
||||
-
|
||||
<Logger name="org.apache.logging.log4j.test2" level="debug" additivity="false">
|
||||
<AppenderRef ref="File"/>
|
||||
</Logger>
|
||||
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
|
||||
index 2c701e2..e9d3f3b 100644
|
||||
--- a/src/changes/changes.xml
|
||||
+++ b/src/changes/changes.xml
|
||||
@@ -134,6 +134,12 @@
|
||||
<action issue="LOG4J2-2667" dev="ggregory" type="fix" due-to="Gary Gregory, Edith Chui">
|
||||
"Values not bound to statement" when using JDBC appender, appender does not respect bufferSize="0".
|
||||
</action>
|
||||
+ <action issue="LOG4J2-2744" dev="ckozak" type="fix">
|
||||
+ Remove unnecessary EventLogger references from log4j-slf4j18-impl due to removal from slf4j.
|
||||
+ </action>
|
||||
+ <action issue="LOG4J2-2745" dev="ckozak" type="update">
|
||||
+ Update log4j-slf4j18-impl slf4j version to 1.8.0-beta4 from 1.8.0-alpha2.
|
||||
+ </action>
|
||||
</release>
|
||||
<release version="2.12.0" date="2019-06-23" description="GA Release 2.12.0">
|
||||
<action issue="LOG4J2-2547" dev="rgoers" type="fix">
|
||||
297
logging-log4j-Remove-unsupported-EventDataConverter.patch
Normal file
297
logging-log4j-Remove-unsupported-EventDataConverter.patch
Normal file
@ -0,0 +1,297 @@
|
||||
From b017736fa1b58377b8bf1b89599b274a9cfb9956 Mon Sep 17 00:00:00 2001
|
||||
From: Dinesh Prasanth M K <dmoluguw@redhat.com>
|
||||
Date: Fri, 31 Jan 2020 13:00:05 -0500
|
||||
Subject: [PATCH] Remove unsupported EventDataConverter
|
||||
|
||||
This deletes the EventDataConverter entirely from log4j-slf4j-impl
|
||||
entirely because EventData is not supported in 1.8.
|
||||
|
||||
Signed-off-by: Dinesh Prasanth M K <dmoluguw@redhat.com>
|
||||
---
|
||||
.../logging/slf4j/EventDataConverter.java | 50 --------------
|
||||
.../org/apache/logging/slf4j/Log4jLogger.java | 22 +-----
|
||||
.../org/apache/logging/slf4j/LoggerTest.java | 21 ------
|
||||
.../apache/logging/slf4j/OptionalTest.java | 69 -------------------
|
||||
.../src/test/resources/log4j-test1.xml | 7 --
|
||||
5 files changed, 1 insertion(+), 168 deletions(-)
|
||||
delete mode 100644 log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/EventDataConverter.java
|
||||
delete mode 100644 log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/OptionalTest.java
|
||||
|
||||
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 620232a..0000000
|
||||
--- a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/EventDataConverter.java
|
||||
+++ /dev/null
|
||||
@@ -1,50 +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 ec4decb..21cbbb6 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
|
||||
@@ -27,9 +27,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.impl.StaticMarkerBinder;
|
||||
import org.slf4j.spi.LocationAwareLogger;
|
||||
|
||||
@@ -41,17 +39,11 @@ 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 final boolean eventLogger;
|
||||
private transient ExtendedLogger logger;
|
||||
private final String name;
|
||||
- private transient EventDataConverter converter;
|
||||
-
|
||||
public Log4jLogger(final ExtendedLogger logger, final String name) {
|
||||
this.logger = logger;
|
||||
- this.eventLogger = "EventLogger".equals(name);
|
||||
this.name = name;
|
||||
- this.converter = createConverter();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -363,9 +355,7 @@ public class Log4jLogger implements LocationAwareLogger, Serializable {
|
||||
return;
|
||||
}
|
||||
final Message msg;
|
||||
- if (eventLogger && marker != null && marker.contains(EVENT_MARKER) && converter != null) {
|
||||
- msg = converter.convertEvent(message, params, throwable);
|
||||
- } else if (params == null) {
|
||||
+ if (params == null) {
|
||||
msg = new SimpleMessage(message);
|
||||
} else {
|
||||
msg = new ParameterizedMessage(message, params, throwable);
|
||||
@@ -400,7 +390,6 @@ public class Log4jLogger implements LocationAwareLogger, Serializable {
|
||||
// always perform the default de-serialization first
|
||||
aInputStream.defaultReadObject();
|
||||
logger = LogManager.getContext().getLogger(name);
|
||||
- converter = createConverter();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -411,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 0524074..c60f1ad 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.junit.LoggerContextRule;
|
||||
import org.apache.logging.log4j.test.appender.ListAppender;
|
||||
@@ -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;
|
||||
@@ -145,23 +142,6 @@ public class LoggerTest {
|
||||
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);
|
||||
- }
|
||||
-
|
||||
private void verify(final String name, final String expected) {
|
||||
final ListAppender listApp = ctx.getListAppender(name);
|
||||
assertNotNull("Missing Appender", listApp);
|
||||
@@ -177,6 +157,5 @@ public class LoggerTest {
|
||||
public void cleanup() {
|
||||
MDC.clear();
|
||||
ctx.getListAppender("List").clear();
|
||||
- ctx.getListAppender("EventLogger").clear();
|
||||
}
|
||||
}
|
||||
diff --git a/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/OptionalTest.java b/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/OptionalTest.java
|
||||
deleted file mode 100644
|
||||
index a6e9fd5..0000000
|
||||
--- a/log4j-slf4j-impl/src/test/java/org/apache/logging/slf4j/OptionalTest.java
|
||||
+++ /dev/null
|
||||
@@ -1,69 +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.List;
|
||||
-
|
||||
-import org.apache.logging.log4j.junit.LoggerContextRule;
|
||||
-import org.apache.logging.log4j.test.appender.ListAppender;
|
||||
-import org.apache.logging.log4j.util.Strings;
|
||||
-import org.junit.Before;
|
||||
-import org.junit.ClassRule;
|
||||
-import org.junit.Test;
|
||||
-import org.slf4j.Logger;
|
||||
-import org.slf4j.LoggerFactory;
|
||||
-import org.slf4j.MDC;
|
||||
-import org.slf4j.Marker;
|
||||
-import org.slf4j.MarkerFactory;
|
||||
-
|
||||
-import static org.junit.Assert.*;
|
||||
-
|
||||
-/**
|
||||
- *
|
||||
- */
|
||||
-public class OptionalTest {
|
||||
-
|
||||
- private static final String CONFIG = "log4j-test1.xml";
|
||||
-
|
||||
- @ClassRule
|
||||
- public static final LoggerContextRule CTX = new LoggerContextRule(CONFIG);
|
||||
-
|
||||
- Logger logger = LoggerFactory.getLogger("EventLogger");
|
||||
- Marker marker = MarkerFactory.getMarker("EVENT");
|
||||
-
|
||||
- @Test
|
||||
- public void testEventLogger() {
|
||||
- logger.info(marker, "This is a test");
|
||||
- MDC.clear();
|
||||
- verify("EventLogger", "o.a.l.s.OptionalTest This is a test" + Strings.LINE_SEPARATOR);
|
||||
- }
|
||||
-
|
||||
- private void verify(final String name, final String expected) {
|
||||
- final ListAppender listApp = CTX.getListAppender(name);
|
||||
- final List<String> events = listApp.getMessages();
|
||||
- assertTrue("Incorrect number of messages. Expected 1 Actual " + events.size(), events.size()== 1);
|
||||
- final String actual = events.get(0);
|
||||
- assertEquals("Incorrect message. Expected " + expected + ". Actual " + actual, expected, actual);
|
||||
- listApp.clear();
|
||||
- }
|
||||
-
|
||||
- @Before
|
||||
- public void cleanup() {
|
||||
- CTX.getListAppender("List").clear();
|
||||
- CTX.getListAppender("EventLogger").clear();
|
||||
- }
|
||||
-}
|
||||
diff --git a/log4j-slf4j-impl/src/test/resources/log4j-test1.xml b/log4j-slf4j-impl/src/test/resources/log4j-test1.xml
|
||||
index a64bdfa..07a2be6 100644
|
||||
--- a/log4j-slf4j-impl/src/test/resources/log4j-test1.xml
|
||||
+++ b/log4j-slf4j-impl/src/test/resources/log4j-test1.xml
|
||||
@@ -6,9 +6,6 @@
|
||||
<ThresholdFilter level="trace"/>
|
||||
|
||||
<Appenders>
|
||||
- <List name="EventLogger">
|
||||
- <PatternLayout pattern="%C{1.} %m%n"/>
|
||||
- </List>
|
||||
<Console name="STDOUT">
|
||||
<PatternLayout pattern="%C{1.} %m MDC%X%n"/>
|
||||
</Console>
|
||||
@@ -24,10 +21,6 @@
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
- <Logger name="EventLogger" level="info" additivity="false">
|
||||
- <AppenderRef ref="EventLogger"/>
|
||||
- </Logger>>
|
||||
-
|
||||
<Logger name="org.apache.logging.log4j.test2" level="debug" additivity="false">
|
||||
<AppenderRef ref="File"/>
|
||||
</Logger>
|
||||
--
|
||||
2.23.0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user