This is an automated email from the ASF dual-hosted git repository. coheigea pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cxf.git
commit 504f94782d3078762425f1a646dbd57c3d645132 Author: Colm O hEigeartaigh <[email protected]> AuthorDate: Fri Apr 17 15:55:39 2020 +0100 CXF-8264 - Remove Log4J 1.x dependencies --- core/pom.xml | 7 - .../org/apache/cxf/common/logging/Log4jLogger.java | 209 --------------------- distribution/javadoc/pom.xml | 4 - .../apache/cxf/jca/core/logging/LoggerHelper.java | 8 - osgi/bundle/compatible/pom.xml | 1 - parent/pom.xml | 34 ---- services/sts/sts-core/pom.xml | 6 - .../cxf/sts/event/LoggerPatternLayoutLog4J.java | 46 ----- services/wsn/wsn-osgi/pom.xml | 1 - 9 files changed, 316 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 81c98e8..d768e3e 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -43,7 +43,6 @@ org.codehaus.stax2*;resolution:=optional, com.sun*;resolution:=optional, org.slf4j*;resolution:=optional;version="${cxf.osgi.slf4j.version}", - org.apache.log4j*;resolution:=optional, net.sf.cglib*;resolution:=optional;version="${cxf.cglib.osgi.version}", org.springframework.osgi.io;resolution:=optional;version="${cxf.osgi.spring.osgi.version}", org.springframework.osgi.util;resolution:=optional;version="${cxf.osgi.spring.osgi.version}", @@ -107,12 +106,6 @@ <artifactId>jaxb-runtime</artifactId> </dependency> <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <optional>true</optional> - <scope>provided</scope> - </dependency> - <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <optional>true</optional> diff --git a/core/src/main/java/org/apache/cxf/common/logging/Log4jLogger.java b/core/src/main/java/org/apache/cxf/common/logging/Log4jLogger.java deleted file mode 100644 index 29a330e..0000000 --- a/core/src/main/java/org/apache/cxf/common/logging/Log4jLogger.java +++ /dev/null @@ -1,209 +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.cxf.common.logging; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.LogRecord; - -import org.apache.log4j.Appender; -import org.apache.log4j.AppenderSkeleton; -import org.apache.log4j.Priority; -import org.apache.log4j.spi.LoggingEvent; - -/** - * java.util.logging.Logger implementation delegating to Log4j. - * All methods can be used except: - * setLevel - * addHandler / getHandlers - * setParent / getParent - * setUseParentHandlers / getUseParentHandlers - */ -public class Log4jLogger extends AbstractDelegatingLogger { - private static final Map<Level, org.apache.log4j.Level> TO_LOG4J = - new HashMap<>(); - private static final org.apache.log4j.Level TRACE; - - - private final org.apache.log4j.Logger log; - - static { - //older versions of log4j don't have TRACE, use debug - org.apache.log4j.Level t = org.apache.log4j.Level.DEBUG; - try { - Field f = org.apache.log4j.Level.class.getField("TRACE"); - t = (org.apache.log4j.Level)f.get(null); - } catch (Throwable ex) { - //ignore, assume old version of log4j - } - TRACE = t; - - TO_LOG4J.put(Level.ALL, org.apache.log4j.Level.ALL); - TO_LOG4J.put(Level.SEVERE, org.apache.log4j.Level.ERROR); - TO_LOG4J.put(Level.WARNING, org.apache.log4j.Level.WARN); - TO_LOG4J.put(Level.INFO, org.apache.log4j.Level.INFO); - TO_LOG4J.put(Level.CONFIG, org.apache.log4j.Level.DEBUG); - TO_LOG4J.put(Level.FINE, org.apache.log4j.Level.DEBUG); - TO_LOG4J.put(Level.FINER, TRACE); - TO_LOG4J.put(Level.FINEST, TRACE); - TO_LOG4J.put(Level.OFF, org.apache.log4j.Level.OFF); - } - - public Log4jLogger(String name, String resourceBundleName) { - super(name, resourceBundleName); - log = org.apache.log4j.LogManager.getLogger(name); - } - - public Level getLevel() { - org.apache.log4j.Level l = log.getEffectiveLevel(); - if (l != null) { - return fromL4J(l); - } - return null; - } - - public void setLevel(Level newLevel) { - log.setLevel(TO_LOG4J.get(newLevel)); - } - - public synchronized void addHandler(Handler handler) { - log.addAppender(new HandlerWrapper(handler)); - } - public synchronized void removeHandler(Handler handler) { - log.removeAppender("HandlerWrapper-" + handler.hashCode()); - } - public synchronized Handler[] getHandlers() { - List<Handler> ret = new ArrayList<>(); - Enumeration<?> en = log.getAllAppenders(); - while (en.hasMoreElements()) { - Appender ap = (Appender)en.nextElement(); - if (ap instanceof HandlerWrapper) { - ret.add(((HandlerWrapper)ap).getHandler()); - } - } - return ret.toArray(new Handler[0]); - } - - protected void internalLogFormatted(String msg, LogRecord record) { - log.log(AbstractDelegatingLogger.class.getName(), - TO_LOG4J.get(record.getLevel()), - msg, - record.getThrown()); - } - - - private Level fromL4J(org.apache.log4j.Level l) { - Level l2 = null; - switch (l.toInt()) { - case org.apache.log4j.Priority.ALL_INT: - l2 = Level.ALL; - break; - case org.apache.log4j.Priority.FATAL_INT: - l2 = Level.SEVERE; - break; - case org.apache.log4j.Priority.ERROR_INT: - l2 = Level.SEVERE; - break; - case org.apache.log4j.Priority.WARN_INT: - l2 = Level.WARNING; - break; - case org.apache.log4j.Priority.INFO_INT: - l2 = Level.INFO; - break; - case org.apache.log4j.Priority.DEBUG_INT: - l2 = Level.FINE; - break; - case org.apache.log4j.Priority.OFF_INT: - l2 = Level.OFF; - break; - default: - if (l.toInt() == TRACE.toInt()) { - l2 = Level.FINEST; - } - } - return l2; - } - - - private class HandlerWrapper extends AppenderSkeleton { - Handler handler; - - HandlerWrapper(Handler h) { - handler = h; - name = "HandlerWrapper-" + h.hashCode(); - } - - public Handler getHandler() { - return handler; - } - - @Override - protected void append(LoggingEvent event) { - LogRecord lr = new LogRecord(fromL4J(event.getLevel()), - event.getMessage().toString()); - lr.setLoggerName(event.getLoggerName()); - if (event.getThrowableInformation() != null) { - lr.setThrown(event.getThrowableInformation().getThrowable()); - } - String rbname = getResourceBundleName(); - if (rbname != null) { - lr.setResourceBundleName(rbname); - lr.setResourceBundle(getResourceBundle()); - } - getFullInfoForLogUtils(lr, event.fqnOfCategoryClass); - handler.publish(lr); - } - - public void close() { - handler.close(); - closed = true; - } - - public boolean requiresLayout() { - return false; - } - - @Override - public Priority getThreshold() { - return TO_LOG4J.get(handler.getLevel()); - } - @Override - public boolean isAsSevereAsThreshold(Priority priority) { - Priority p = getThreshold(); - return (p == null) || priority.isGreaterOrEqual(p); - } - } - private static void getFullInfoForLogUtils(LogRecord lr, String cname) { - StackTraceElement[] el = Thread.currentThread().getStackTrace(); - for (int x = el.length - 2; x >= 0; x--) { - if (LogUtils.class.getName().equals(el[x].getClassName()) - || cname.equals(el[x].getClassName())) { - lr.setSourceClassName(el[x + 1].getClassName()); - lr.setSourceMethodName(el[x + 1].getMethodName()); - return; - } - } - } -} diff --git a/distribution/javadoc/pom.xml b/distribution/javadoc/pom.xml index 85eb061..72e4770 100644 --- a/distribution/javadoc/pom.xml +++ b/distribution/javadoc/pom.xml @@ -135,10 +135,6 @@ <artifactId>xml-resolver</artifactId> </dependency> <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </dependency> - <dependency> <groupId>jakarta.validation</groupId> <artifactId>jakarta.validation-api</artifactId> </dependency> diff --git a/integration/jca/src/main/java/org/apache/cxf/jca/core/logging/LoggerHelper.java b/integration/jca/src/main/java/org/apache/cxf/jca/core/logging/LoggerHelper.java index 8131a44..6991270 100644 --- a/integration/jca/src/main/java/org/apache/cxf/jca/core/logging/LoggerHelper.java +++ b/integration/jca/src/main/java/org/apache/cxf/jca/core/logging/LoggerHelper.java @@ -24,7 +24,6 @@ import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; -import org.apache.cxf.common.logging.Log4jLogger; import org.apache.cxf.common.logging.LogUtils; @@ -42,13 +41,6 @@ public final class LoggerHelper { public static void initializeLoggingOnWriter(final Writer writer) { if (writer != null) { - if (writer.getClass().getName().startsWith("org.jboss")) { - // jboss writer will redirect to log4j which will cause an - // infinite loop if we install an appender over this writer. - // Continue logging via log4j and ignore this writer. - LogUtils.setLoggerClass(Log4jLogger.class); - return; - } Logger cxfLogger = getRootCXFLogger(); diff --git a/osgi/bundle/compatible/pom.xml b/osgi/bundle/compatible/pom.xml index 43b54c4..baf3b6a 100644 --- a/osgi/bundle/compatible/pom.xml +++ b/osgi/bundle/compatible/pom.xml @@ -167,7 +167,6 @@ org.apache.commons.lang3*;resolution:=optional;version="[3,4)", org.apache.commons.codec*;resolution:=optional, org.apache.commons.pool*;resolution:=optional, - org.apache.log4j*;resolution:=optional, org.apache.mina*;resolution:=optional, org.apache.velocity*;resolution:=optional, org.apache.xml.security*;resolution:=optional, diff --git a/parent/pom.xml b/parent/pom.xml index ddf1edf..2c07488 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -157,7 +157,6 @@ <cxf.junit.version>4.13</cxf.junit.version> <cxf.kerby.version>2.0.0</cxf.kerby.version> <cxf.littleproxy.version>1.1.2</cxf.littleproxy.version> - <cxf.log4j.version>1.2.17</cxf.log4j.version> <cxf.logback.classic.version>1.2.3</cxf.logback.classic.version> <cxf.lucene.version>8.2.0</cxf.lucene.version> <cxf.maven.core.version>3.6.2</cxf.maven.core.version> @@ -1269,11 +1268,6 @@ </dependency> <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>${cxf.log4j.version}</version> - </dependency> - <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>${cxf.logback.classic.version}</version> @@ -1500,10 +1494,6 @@ <version>${cxf.neethi.version}</version> <exclusions> <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> @@ -1746,10 +1736,6 @@ <version>${cxf.spring.version}</version> <exclusions> <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> @@ -1773,10 +1759,6 @@ <version>${cxf.spring.version}</version> <exclusions> <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> @@ -1800,10 +1782,6 @@ <version>${cxf.spring.version}</version> <exclusions> <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> @@ -1827,10 +1805,6 @@ <version>${cxf.spring.version}</version> <exclusions> <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> @@ -1854,10 +1828,6 @@ <version>${cxf.spring.version}</version> <exclusions> <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> @@ -1881,10 +1851,6 @@ <version>${cxf.spring.version}</version> <exclusions> <exclusion> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - </exclusion> - <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> diff --git a/services/sts/sts-core/pom.xml b/services/sts/sts-core/pom.xml index 90203f3..47f29e6 100644 --- a/services/sts/sts-core/pom.xml +++ b/services/sts/sts-core/pom.xml @@ -117,12 +117,6 @@ <optional>true</optional> </dependency> <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <scope>provided</scope> - <optional>true</optional> - </dependency> - <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <scope>provided</scope> diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/LoggerPatternLayoutLog4J.java b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/LoggerPatternLayoutLog4J.java deleted file mode 100644 index 4f45307..0000000 --- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/LoggerPatternLayoutLog4J.java +++ /dev/null @@ -1,46 +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.cxf.sts.event; - -import org.apache.cxf.sts.event.map.MapEventLogger; -import org.apache.log4j.PatternLayout; - -public class LoggerPatternLayoutLog4J extends PatternLayout { - - private String header; - - public void setHeader(String header) { - this.header = header; - } - - @Override - public String getHeader() { - if (this.header != null) { - return this.header + System.getProperty("line.separator"); - } - MapEventLogger ll = new MapEventLogger(); - StringBuilder line = new StringBuilder(); - for (String item : ll.getFieldOrder()) { - line.append(item).append(';'); - } - return line.toString() + System.getProperty("line.separator"); - } - -} diff --git a/services/wsn/wsn-osgi/pom.xml b/services/wsn/wsn-osgi/pom.xml index b452b01..0b67553 100644 --- a/services/wsn/wsn-osgi/pom.xml +++ b/services/wsn/wsn-osgi/pom.xml @@ -61,7 +61,6 @@ <Import-Package> org.apache.cxf.*;resolution:=optional, !org.apache.activemq*, - !org.apache.log4j.*, !org.slf4j.*, javax.xml.bind*;version="[0.0,3)", javax.jws*;version="[0.0,3)",
