From fe074f816b6195ce5f0feccdd59f31a1f9625e6d Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Tue, 14 Dec 2021 22:34:57 +0100 Subject: [PATCH] Remove Log4j v1 support completely, even with log4j-1.2-api bridge --- common/pom.xml | 5 - .../logging/InternalLoggerFactory.java | 18 - .../util/internal/logging/Log4JLogger.java | 597 ------------------ .../internal/logging/Log4JLoggerFactory.java | 40 -- pom.xml | 49 +- 5 files changed, 25 insertions(+), 684 deletions(-) delete mode 100644 common/src/main/java/io/netty/util/internal/logging/Log4JLogger.java delete mode 100644 common/src/main/java/io/netty/util/internal/logging/Log4JLoggerFactory.java diff --git a/common/pom.xml b/common/pom.xml index 9dfba340838..9c2cfe2c6c6 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -63,11 +63,6 @@ commons-logging true - - org.apache.logging.log4j - log4j-1.2-api - true - org.apache.logging.log4j log4j-api diff --git a/common/src/main/java/io/netty/util/internal/logging/InternalLoggerFactory.java b/common/src/main/java/io/netty/util/internal/logging/InternalLoggerFactory.java index 7ad7db8a011..80e6ce24807 100644 --- a/common/src/main/java/io/netty/util/internal/logging/InternalLoggerFactory.java +++ b/common/src/main/java/io/netty/util/internal/logging/InternalLoggerFactory.java @@ -49,11 +49,6 @@ private static InternalLoggerFactory newDefaultFactory(String name) { return f; } - f = useLog4JLoggerFactory(name); - if (f != null) { - return f; - } - return useJdkLoggerFactory(name); } @@ -83,19 +78,6 @@ private static InternalLoggerFactory useLog4J2LoggerFactory(String name) { } } - private static InternalLoggerFactory useLog4JLoggerFactory(String name) { - try { - InternalLoggerFactory f = Log4JLoggerFactory.INSTANCE; - f.newInstance(name).debug("Using Log4J as the default logging framework"); - return f; - } catch (LinkageError ignore) { - return null; - } catch (Exception ignore) { - // We catch Exception and not ReflectiveOperationException as we still support java 6 - return null; - } - } - private static InternalLoggerFactory useJdkLoggerFactory(String name) { InternalLoggerFactory f = JdkLoggerFactory.INSTANCE; f.newInstance(name).debug("Using java.util.logging as the default logging framework"); diff --git a/common/src/main/java/io/netty/util/internal/logging/Log4JLogger.java b/common/src/main/java/io/netty/util/internal/logging/Log4JLogger.java deleted file mode 100644 index 8865c1057a2..00000000000 --- a/common/src/main/java/io/netty/util/internal/logging/Log4JLogger.java +++ /dev/null @@ -1,597 +0,0 @@ -/* - * Copyright 2012 The Netty Project - * - * The Netty Project 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: - * - * https://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. - */ -/** - * Copyright (c) 2004-2011 QOS.ch - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ -package io.netty.util.internal.logging; - -import org.apache.log4j.Level; -import org.apache.log4j.Logger; - -/** - * Apache Log4J - * logger. - */ -class Log4JLogger extends AbstractInternalLogger { - - private static final long serialVersionUID = 2851357342488183058L; - - final transient Logger logger; - - /** - * Following the pattern discussed in pages 162 through 168 of "The complete - * log4j manual". - */ - static final String FQCN = Log4JLogger.class.getName(); - - // Does the log4j version in use recognize the TRACE level? - // The trace level was introduced in log4j 1.2.12. - final boolean traceCapable; - - Log4JLogger(Logger logger) { - super(logger.getName()); - this.logger = logger; - traceCapable = isTraceCapable(); - } - - private boolean isTraceCapable() { - try { - logger.isTraceEnabled(); - return true; - } catch (NoSuchMethodError ignored) { - return false; - } - } - - /** - * Is this logger instance enabled for the TRACE level? - * - * @return True if this Logger is enabled for level TRACE, false otherwise. - */ - @Override - public boolean isTraceEnabled() { - if (traceCapable) { - return logger.isTraceEnabled(); - } else { - return logger.isDebugEnabled(); - } - } - - /** - * Log a message object at level TRACE. - * - * @param msg - * - the message object to be logged - */ - @Override - public void trace(String msg) { - logger.log(FQCN, traceCapable ? Level.TRACE : Level.DEBUG, msg, null); - } - - /** - * Log a message at level TRACE according to the specified format and - * argument. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for level TRACE. - *

- * - * @param format - * the format string - * @param arg - * the argument - */ - @Override - public void trace(String format, Object arg) { - if (isTraceEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, arg); - logger.log(FQCN, traceCapable ? Level.TRACE : Level.DEBUG, ft - .getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level TRACE according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the TRACE level. - *

- * - * @param format - * the format string - * @param argA - * the first argument - * @param argB - * the second argument - */ - @Override - public void trace(String format, Object argA, Object argB) { - if (isTraceEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, argA, argB); - logger.log(FQCN, traceCapable ? Level.TRACE : Level.DEBUG, ft - .getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level TRACE according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the TRACE level. - *

- * - * @param format - * the format string - * @param arguments - * an array of arguments - */ - @Override - public void trace(String format, Object... arguments) { - if (isTraceEnabled()) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments); - logger.log(FQCN, traceCapable ? Level.TRACE : Level.DEBUG, ft - .getMessage(), ft.getThrowable()); - } - } - - /** - * Log an exception (throwable) at level TRACE with an accompanying message. - * - * @param msg - * the message accompanying the exception - * @param t - * the exception (throwable) to log - */ - @Override - public void trace(String msg, Throwable t) { - logger.log(FQCN, traceCapable ? Level.TRACE : Level.DEBUG, msg, t); - } - - /** - * Is this logger instance enabled for the DEBUG level? - * - * @return True if this Logger is enabled for level DEBUG, false otherwise. - */ - @Override - public boolean isDebugEnabled() { - return logger.isDebugEnabled(); - } - - /** - * Log a message object at level DEBUG. - * - * @param msg - * - the message object to be logged - */ - @Override - public void debug(String msg) { - logger.log(FQCN, Level.DEBUG, msg, null); - } - - /** - * Log a message at level DEBUG according to the specified format and - * argument. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for level DEBUG. - *

- * - * @param format - * the format string - * @param arg - * the argument - */ - @Override - public void debug(String format, Object arg) { - if (logger.isDebugEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, arg); - logger.log(FQCN, Level.DEBUG, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level DEBUG according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the DEBUG level. - *

- * - * @param format - * the format string - * @param argA - * the first argument - * @param argB - * the second argument - */ - @Override - public void debug(String format, Object argA, Object argB) { - if (logger.isDebugEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, argA, argB); - logger.log(FQCN, Level.DEBUG, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level DEBUG according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the DEBUG level. - *

- * - * @param format - * the format string - * @param arguments an array of arguments - */ - @Override - public void debug(String format, Object... arguments) { - if (logger.isDebugEnabled()) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments); - logger.log(FQCN, Level.DEBUG, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log an exception (throwable) at level DEBUG with an accompanying message. - * - * @param msg - * the message accompanying the exception - * @param t - * the exception (throwable) to log - */ - @Override - public void debug(String msg, Throwable t) { - logger.log(FQCN, Level.DEBUG, msg, t); - } - - /** - * Is this logger instance enabled for the INFO level? - * - * @return True if this Logger is enabled for the INFO level, false otherwise. - */ - @Override - public boolean isInfoEnabled() { - return logger.isInfoEnabled(); - } - - /** - * Log a message object at the INFO level. - * - * @param msg - * - the message object to be logged - */ - @Override - public void info(String msg) { - logger.log(FQCN, Level.INFO, msg, null); - } - - /** - * Log a message at level INFO according to the specified format and argument. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the INFO level. - *

- * - * @param format - * the format string - * @param arg - * the argument - */ - @Override - public void info(String format, Object arg) { - if (logger.isInfoEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, arg); - logger.log(FQCN, Level.INFO, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at the INFO level according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the INFO level. - *

- * - * @param format - * the format string - * @param argA - * the first argument - * @param argB - * the second argument - */ - @Override - public void info(String format, Object argA, Object argB) { - if (logger.isInfoEnabled()) { - FormattingTuple ft = MessageFormatter.format(format, argA, argB); - logger.log(FQCN, Level.INFO, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level INFO according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the INFO level. - *

- * - * @param format - * the format string - * @param argArray - * an array of arguments - */ - @Override - public void info(String format, Object... argArray) { - if (logger.isInfoEnabled()) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray); - logger.log(FQCN, Level.INFO, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log an exception (throwable) at the INFO level with an accompanying - * message. - * - * @param msg - * the message accompanying the exception - * @param t - * the exception (throwable) to log - */ - @Override - public void info(String msg, Throwable t) { - logger.log(FQCN, Level.INFO, msg, t); - } - - /** - * Is this logger instance enabled for the WARN level? - * - * @return True if this Logger is enabled for the WARN level, false otherwise. - */ - @Override - public boolean isWarnEnabled() { - return logger.isEnabledFor(Level.WARN); - } - - /** - * Log a message object at the WARN level. - * - * @param msg - * - the message object to be logged - */ - @Override - public void warn(String msg) { - logger.log(FQCN, Level.WARN, msg, null); - } - - /** - * Log a message at the WARN level according to the specified format and - * argument. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the WARN level. - *

- * - * @param format - * the format string - * @param arg - * the argument - */ - @Override - public void warn(String format, Object arg) { - if (logger.isEnabledFor(Level.WARN)) { - FormattingTuple ft = MessageFormatter.format(format, arg); - logger.log(FQCN, Level.WARN, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at the WARN level according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the WARN level. - *

- * - * @param format - * the format string - * @param argA - * the first argument - * @param argB - * the second argument - */ - @Override - public void warn(String format, Object argA, Object argB) { - if (logger.isEnabledFor(Level.WARN)) { - FormattingTuple ft = MessageFormatter.format(format, argA, argB); - logger.log(FQCN, Level.WARN, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level WARN according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the WARN level. - *

- * - * @param format - * the format string - * @param argArray - * an array of arguments - */ - @Override - public void warn(String format, Object... argArray) { - if (logger.isEnabledFor(Level.WARN)) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray); - logger.log(FQCN, Level.WARN, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log an exception (throwable) at the WARN level with an accompanying - * message. - * - * @param msg - * the message accompanying the exception - * @param t - * the exception (throwable) to log - */ - @Override - public void warn(String msg, Throwable t) { - logger.log(FQCN, Level.WARN, msg, t); - } - - /** - * Is this logger instance enabled for level ERROR? - * - * @return True if this Logger is enabled for level ERROR, false otherwise. - */ - @Override - public boolean isErrorEnabled() { - return logger.isEnabledFor(Level.ERROR); - } - - /** - * Log a message object at the ERROR level. - * - * @param msg - * - the message object to be logged - */ - @Override - public void error(String msg) { - logger.log(FQCN, Level.ERROR, msg, null); - } - - /** - * Log a message at the ERROR level according to the specified format and - * argument. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the ERROR level. - *

- * - * @param format - * the format string - * @param arg - * the argument - */ - @Override - public void error(String format, Object arg) { - if (logger.isEnabledFor(Level.ERROR)) { - FormattingTuple ft = MessageFormatter.format(format, arg); - logger.log(FQCN, Level.ERROR, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at the ERROR level according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the ERROR level. - *

- * - * @param format - * the format string - * @param argA - * the first argument - * @param argB - * the second argument - */ - @Override - public void error(String format, Object argA, Object argB) { - if (logger.isEnabledFor(Level.ERROR)) { - FormattingTuple ft = MessageFormatter.format(format, argA, argB); - logger.log(FQCN, Level.ERROR, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log a message at level ERROR according to the specified format and - * arguments. - * - *

- * This form avoids superfluous object creation when the logger is disabled - * for the ERROR level. - *

- * - * @param format - * the format string - * @param argArray - * an array of arguments - */ - @Override - public void error(String format, Object... argArray) { - if (logger.isEnabledFor(Level.ERROR)) { - FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray); - logger.log(FQCN, Level.ERROR, ft.getMessage(), ft.getThrowable()); - } - } - - /** - * Log an exception (throwable) at the ERROR level with an accompanying - * message. - * - * @param msg - * the message accompanying the exception - * @param t - * the exception (throwable) to log - */ - @Override - public void error(String msg, Throwable t) { - logger.log(FQCN, Level.ERROR, msg, t); - } -} diff --git a/common/src/main/java/io/netty/util/internal/logging/Log4JLoggerFactory.java b/common/src/main/java/io/netty/util/internal/logging/Log4JLoggerFactory.java deleted file mode 100644 index 3d56907f38d..00000000000 --- a/common/src/main/java/io/netty/util/internal/logging/Log4JLoggerFactory.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012 The Netty Project - * - * The Netty Project 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: - * - * https://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 io.netty.util.internal.logging; - -import org.apache.log4j.Logger; - -/** - * Logger factory which creates an - * Apache Log4J - * logger. - */ -public class Log4JLoggerFactory extends InternalLoggerFactory { - - public static final InternalLoggerFactory INSTANCE = new Log4JLoggerFactory(); - - /** - * @deprecated Use {@link #INSTANCE} instead. - */ - @Deprecated - public Log4JLoggerFactory() { - } - - @Override - public InternalLogger newInstance(String name) { - return new Log4JLogger(Logger.getLogger(name)); - } -} diff --git a/pom.xml b/pom.xml index d0691b828e6..555f6b97ac7 100644 --- a/pom.xml +++ b/pom.xml @@ -783,30 +783,6 @@ log4j-api ${log4j2.version}
- - org.apache.logging.log4j - log4j-1.2-api - 2.15.0 - - - mail - javax.mail - - - jms - javax.jms - - - jmxtools - com.sun.jdmk - - - jmxri - com.sun.jmx - - - true - @@ -1048,6 +1024,12 @@ java-package /org\.openjdk\.jmh\..*/ + java @io.netty.util.internal.UnstableApi ^*; @@ -1076,6 +1058,18 @@ missing-class org.slf4j.Logger The com.barchart.udt library exposes this class in their API, but slf4j is an optional dependency to Netty. + + true + java.class.removed + public class io.netty.util.internal.logging.Log4JLoggerFactory + + Log4j v1 (not v2) support was fully removed, because Log4j v1 is an unmaintained version with known security vulnerabilities + true java.class.externalClassExposedInAPI @@ -1090,6 +1084,13 @@ .*\.generated($|\..+) Ignore all classes generated by JMH. + + true + java.class.removed + true + .*\.internal($|\..+) + Ignore all internal packages +