From 54e32e711ac596cb9101500d866a30f0812217f9 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Mon, 6 Feb 2012 23:55:13 +0000 Subject: [PATCH 01/65] Make new home for Log4j2 git-svn-id: https://svn.apache.org/repos/asf/logging/log4j/log4j2/trunk@1241269 13f79535-47bb-0310-9956-ffa450edef68 From cd18eb5fe04058722d4c241050508aee7c096008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vorburger=20=E2=9B=91=EF=B8=8F?= Date: Fri, 7 Jan 2022 22:55:48 +0100 Subject: [PATCH 02/65] LOG4J2-3282: log4j-to-jul JDK Logging Bridge (#653) --- log4j-to-jul/pom.xml | 175 ++++++++++++ .../apache/logging/log4j/tojul/JULLogger.java | 267 ++++++++++++++++++ .../logging/log4j/tojul/JULLoggerContext.java | 72 +++++ .../log4j/tojul/JULLoggerContextFactory.java | 72 +++++ .../logging/log4j/tojul/JULProvider.java | 30 ++ .../logging/log4j/tojul/package-info.java | 23 ++ .../org.apache.logging.log4j.spi.Provider | 18 ++ log4j-to-jul/src/site/markdown/index.md | 41 +++ log4j-to-jul/src/site/site.xml | 52 ++++ .../logging/log4j/tojul/LoggerTest.java | 204 +++++++++++++ 10 files changed, 954 insertions(+) create mode 100644 log4j-to-jul/pom.xml create mode 100644 log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java create mode 100644 log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java create mode 100644 log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContextFactory.java create mode 100644 log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java create mode 100644 log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java create mode 100644 log4j-to-jul/src/main/resources/META-INF/services/org.apache.logging.log4j.spi.Provider create mode 100644 log4j-to-jul/src/site/markdown/index.md create mode 100644 log4j-to-jul/src/site/site.xml create mode 100644 log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml new file mode 100644 index 0000000..95c209e --- /dev/null +++ b/log4j-to-jul/pom.xml @@ -0,0 +1,175 @@ + + + + 4.0.0 + + org.apache.logging.log4j + log4j + 2.17.2-SNAPSHOT + ../ + + log4j-to-jul + jar + Apache Log4j to JUL Bridge + The Apache Log4j binding between Log4j 2 API and java.util.logging (JUL). + + ${basedir}/.. + Log4j to JUL Documentation + /log4j-to-jul + org.apache.logging.tojul + true + + + + org.apache.logging.log4j + log4j-api + + + com.google.guava + guava-testlib + test + + + org.junit.vintage + junit-vintage-engine + + + org.junit.jupiter + junit-jupiter-engine + + + org.assertj + assertj-core + test + + + + + + + org.apache.maven.plugins + maven-remote-resources-plugin + + + + process + + + false + + + + + + org.apache.felix + maven-bundle-plugin + + + org.apache.logging.tojul + + + + + + + + + org.apache.maven.plugins + maven-changes-plugin + ${changes.plugin.version} + + + + changes-report + + + + + %URL%/show_bug.cgi?id=%ISSUE% + true + + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${checkstyle.plugin.version} + + + ${log4jParentDir}/checkstyle.xml + ${log4jParentDir}/checkstyle-suppressions.xml + false + basedir=${basedir} + licensedir=${log4jParentDir}/checkstyle-header.txt + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${javadoc.plugin.version} + + Copyright © {inceptionYear}-{currentYear} {organizationName}. All Rights Reserved.
+ Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, + and the Apache Log4j logo are trademarks of The Apache Software Foundation.

]]>
+ + false + true +
+ + + non-aggregate + + javadoc + + + +
+ + com.github.spotbugs + spotbugs-maven-plugin + + + org.apache.maven.plugins + maven-jxr-plugin + ${jxr.plugin.version} + + + non-aggregate + + jxr + + + + aggregate + + aggregate + + + + + + org.apache.maven.plugins + maven-pmd-plugin + ${pmd.plugin.version} + + ${maven.compiler.target} + + +
+
+
diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java new file mode 100644 index 0000000..52c5299 --- /dev/null +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java @@ -0,0 +1,267 @@ +/* + * 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.log4j.tojul; + +import static java.util.Objects.requireNonNull; + +import java.util.logging.LogRecord; +import java.util.logging.Logger; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.message.Message; +import org.apache.logging.log4j.message.MessageFactory; +import org.apache.logging.log4j.spi.AbstractLogger; + +/** + * Implementation of {@link org.apache.logging.log4j.Logger} that's backed by a {@link Logger}. + * + * This implementation currently ignores {@link Marker}. + * + * @author Michael Vorburger.ch for Google + */ +final class JULLogger extends AbstractLogger { + private static final long serialVersionUID = 1L; + + private final Logger logger; + + // This implementation is inspired by org.apache.logging.slf4j.SLF4JLogger + + public JULLogger(final String name, final MessageFactory messageFactory, final Logger logger) { + super(name, messageFactory); + this.logger = requireNonNull(logger, "logger"); + } + + public JULLogger(final String name, final Logger logger) { + super(name); + this.logger = requireNonNull(logger, "logger"); + } + + public Logger getWrappedLogger() { + return logger; + } + + @Override + public void logMessage(final String fqcn, final Level level, final Marker marker, final Message message, final Throwable t) { + java.util.logging.Level julLevel = convertLevel(level); + if (!logger.isLoggable(julLevel)) { + return; + } + LogRecord record = new LogRecord(julLevel, message.getFormattedMessage()); // NOT getFormat() + // NOT record.setParameters(message.getParameters()); BECAUSE getFormattedMessage() NOT getFormat() + record.setLoggerName(getName()); + record.setThrown(t == null ? message.getThrowable() : t); + // Source class/method is not supported (yet) + record.setSourceClassName(null); + record.setSourceMethodName(null); + logger.log(record); + // fqcn is un-used + } + + // Convert Level in Log4j scale to JUL scale. + // See getLevel() for the mapping. Note that JUL's FINEST & CONFIG are never returned because Log4j has no such levels, and + // that Log4j's FATAL is simply mapped to JUL's SEVERE as is Log4j's ERROR because JUL does not distinguish between ERROR and FATAL. + private java.util.logging.Level convertLevel(final Level level) { + switch (level.getStandardLevel()) { + // Test in logical order of likely frequency of use + // Must be kept in sync with #getLevel() + case ALL: + return java.util.logging.Level.ALL; + case TRACE: + return java.util.logging.Level.FINER; + case DEBUG: + return java.util.logging.Level.FINE; + case INFO: + return java.util.logging.Level.INFO; + case WARN: + return java.util.logging.Level.WARNING; + case ERROR: + return java.util.logging.Level.SEVERE; + case FATAL: + return java.util.logging.Level.SEVERE; + case OFF: + return java.util.logging.Level.OFF; + default: + // This is tempting: throw new IllegalStateException("Impossible Log4j Level encountered: " + level.intLevel()); + // But it's not a great idea, security wise. If an attacker *SOMEHOW* managed to create a Log4j Level instance + // with an unexpected level (through JVM de-serialization, despite readResolve() { return Level.valueOf(this.name); }, + // or whatever other means), then we would blow up in a very unexpected place and way. Let us therefore instead just + // return SEVERE for unexpected values, because that's more likely to be noticed than a FINER. + // Greetings, Michael Vorburger.ch , for Google, on 2021.12.24. + return java.util.logging.Level.SEVERE; + } + } + + /** + * Level in Log4j scale. + * JUL Levels are mapped as follows: + *
    + *
  • OFF => OFF + *
  • SEVERE => ERROR + *
  • WARNING => WARN + *
  • INFO => INFO + *
  • CONFIG => INFO + *
  • FINE => DEBUG + *
  • FINER => TRACE (as in https://github.com/apache/logging-log4j2/blob/a58a06bf2365165ac5abdde931bb4ecd1adf0b3c/log4j-jul/src/main/java/org/apache/logging/log4j/jul/DefaultLevelConverter.java#L55-L75) + *
  • FINEST => TRACE + *
  • ALL => ALL + *
+ * + * Numeric JUL Levels that don't match the known levels are matched to the closest one. + * For example, anything between OFF (Integer.MAX_VALUE) and SEVERE (1000) is returned as a Log4j FATAL. + */ + @Override + public Level getLevel() { + int julLevel = getEffectiveJULLevel().intValue(); + // Test in logical order of likely frequency of use + // Must be kept in sync with #convertLevel() + if (julLevel == java.util.logging.Level.ALL.intValue()) { + return Level.ALL; + } + if (julLevel <= java.util.logging.Level.FINER.intValue()) { + return Level.TRACE; + } + if (julLevel <= java.util.logging.Level.FINE.intValue()) { // includes FINER + return Level.DEBUG; + } + if (julLevel <= java.util.logging.Level.INFO.intValue()) { // includes CONFIG + return Level.INFO; + } + if (julLevel <= java.util.logging.Level.WARNING.intValue()) { + return Level.WARN; + } + if (julLevel <= java.util.logging.Level.SEVERE.intValue()) { + return Level.ERROR; + } + return Level.OFF; + } + + private java.util.logging.Level getEffectiveJULLevel() { + Logger current = logger; + while (current.getLevel() == null && current.getParent() != null) { + current = current.getParent(); + } + if (current.getLevel() != null) { + return current.getLevel(); + } + // This is a safety fallback that is typically never reached, because usually the root Logger.getLogger("") has a Level. + return Logger.getGlobal().getLevel(); + } + + private boolean isEnabledFor(final Level level, final Marker marker) { + // E.g. we're logging WARN and more, so getLevel() is 300, if we're asked if we're + // enabled for level ERROR which is 200, isLessSpecificThan() tests for >= so return true. + return getLevel().isLessSpecificThan(level); + } + + @Override + public boolean isEnabled(final Level level, final Marker marker, final Message data, final Throwable t) { + return isEnabledFor(level, marker); + } + + @Override + public boolean isEnabled(final Level level, final Marker marker, final CharSequence data, final Throwable t) { + return isEnabledFor(level, marker); + } + + @Override + public boolean isEnabled(final Level level, final Marker marker, final Object data, final Throwable t) { + return isEnabledFor(level, marker); + } + + @Override + public boolean isEnabled(final Level level, final Marker marker, final String data) { + return isEnabledFor(level, marker); + } + + @Override + public boolean isEnabled(final Level level, final Marker marker, final String data, final Object... p1) { + return isEnabledFor(level, marker); + } + + @Override + public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0) { + return isEnabledFor(level, marker); + } + + @Override + public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, + final Object p1) { + return isEnabledFor(level, marker); + } + + @Override + public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, + final Object p1, final Object p2) { + return isEnabledFor(level, marker); + } + + @Override + public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, + final Object p1, final Object p2, final Object p3) { + return isEnabledFor(level, marker); + } + + @Override + public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, + final Object p1, final Object p2, final Object p3, + final Object p4) { + return isEnabledFor(level, marker); + } + + @Override + public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, + final Object p1, final Object p2, final Object p3, + final Object p4, final Object p5) { + return isEnabledFor(level, marker); + } + + @Override + public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, + final Object p1, final Object p2, final Object p3, + final Object p4, final Object p5, final Object p6) { + return isEnabledFor(level, marker); + } + + @Override + public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, + final Object p1, final Object p2, final Object p3, + final Object p4, final Object p5, final Object p6, + final Object p7) { + return isEnabledFor(level, marker); + } + + @Override + public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, + final Object p1, final Object p2, final Object p3, + final Object p4, final Object p5, final Object p6, + final Object p7, final Object p8) { + return isEnabledFor(level, marker); + } + + @Override + public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, + final Object p1, final Object p2, final Object p3, + final Object p4, final Object p5, final Object p6, + final Object p7, final Object p8, final Object p9) { + return isEnabledFor(level, marker); + } + + @Override + public boolean isEnabled(final Level level, final Marker marker, final String data, final Throwable t) { + return isEnabledFor(level, marker); + } +} diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java new file mode 100644 index 0000000..4dca60e --- /dev/null +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java @@ -0,0 +1,72 @@ +/* + * 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.log4j.tojul; + +import java.util.logging.Logger; +import org.apache.logging.log4j.message.MessageFactory; +import org.apache.logging.log4j.spi.ExtendedLogger; +import org.apache.logging.log4j.spi.LoggerContext; +import org.apache.logging.log4j.spi.LoggerRegistry; + +/** + * Implementation of Log4j {@link LoggerContext} SPI. + * This is a factory to produce {@link JULLogger} instances. + * + * @author Michael Vorburger.ch for Google + */ +class JULLoggerContext implements LoggerContext { + private final LoggerRegistry loggerRegistry = new LoggerRegistry<>(); + + // This implementation is strongly inspired by org.apache.logging.slf4j.SLF4JLoggerContext + + @Override + public Object getExternalContext() { + return null; + } + + @Override + public ExtendedLogger getLogger(final String name) { + if (!loggerRegistry.hasLogger(name)) { + loggerRegistry.putIfAbsent(name, null, new JULLogger(name, Logger.getLogger(name))); + } + return loggerRegistry.getLogger(name); + } + + @Override + public ExtendedLogger getLogger(final String name, final MessageFactory messageFactory) { + if (!loggerRegistry.hasLogger(name, messageFactory)) { + loggerRegistry.putIfAbsent(name, messageFactory, + new JULLogger(name, messageFactory, Logger.getLogger(name))); + } + return loggerRegistry.getLogger(name, messageFactory); + } + + @Override + public boolean hasLogger(final String name) { + return loggerRegistry.hasLogger(name); + } + + @Override + public boolean hasLogger(final String name, final MessageFactory messageFactory) { + return loggerRegistry.hasLogger(name, messageFactory); + } + + @Override + public boolean hasLogger(final String name, final Class messageFactoryClass) { + return loggerRegistry.hasLogger(name, messageFactoryClass); + } +} diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContextFactory.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContextFactory.java new file mode 100644 index 0000000..f44a0d4 --- /dev/null +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContextFactory.java @@ -0,0 +1,72 @@ +/* + * 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.log4j.tojul; + +import java.net.URI; +import org.apache.logging.log4j.spi.LoggerContext; +import org.apache.logging.log4j.spi.LoggerContextFactory; +import org.apache.logging.log4j.status.StatusLogger; +import org.apache.logging.log4j.util.LoaderUtil; + +/** + * Implementation of Log4j {@link LoggerContextFactory} SPI. + * This is a factory to produce the (one and only) {@link JULLoggerContext} instance. + * + * @author Michael Vorburger.ch for Google + */ +public class JULLoggerContextFactory implements LoggerContextFactory { + private static final StatusLogger LOGGER = StatusLogger.getLogger(); + private static final LoggerContext context = new JULLoggerContext(); + + // This implementation is strongly inspired by org.apache.logging.slf4j.SLF4JLoggerContextFactory + + public JULLoggerContextFactory() { + boolean misconfigured = false; + try { + LoaderUtil.loadClass("org.apache.logging.log4j.jul.LogManager"); + misconfigured = true; + } catch (final ClassNotFoundException classNotFoundIsGood) { + LOGGER.debug("org.apache.logging.log4j.jul.LogManager is not on classpath. Good!"); + } + if (misconfigured) { + throw new IllegalStateException("log4j-jul JAR is mutually exclusive with the log4j-to-jul JAR" + + "(the first routes calls from Log4j to JUL, the second from Log4j to JUL)"); + } + } + + @Override + public LoggerContext getContext(final String fqcn, final ClassLoader loader, final Object externalContext, + final boolean currentContext) { + return context; + } + + @Override + public LoggerContext getContext(final String fqcn, final ClassLoader loader, final Object externalContext, + final boolean currentContext, final URI configLocation, final String name) { + return context; + } + + @Override + public void removeContext(final LoggerContext ignored) { + } + + @Override + public boolean isClassLoaderDependent() { + // context is always used + return false; + } +} diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java new file mode 100644 index 0000000..2c57ef9 --- /dev/null +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java @@ -0,0 +1,30 @@ +/* + * 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.log4j.tojul; + +import org.apache.logging.log4j.spi.Provider; + +/** + * Bind the Log4j API to JUL. + * + * @author Michael Vorburger.ch for Google + */ +public class JULProvider extends Provider { + public JULProvider() { + super(15, "2.6.0", JULLoggerContextFactory.class, null); + } +} diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java new file mode 100644 index 0000000..b6cd969 --- /dev/null +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java @@ -0,0 +1,23 @@ +/* + * 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. + */ +/** + * Java JDK java.util.logging (JUL) bridge. + * This sends all Log4j logs to JUL (not the other way around, there is another module for the opposite direction). + * + * @author Michael Vorburger.ch for Google + */ +package org.apache.logging.log4j.tojul; diff --git a/log4j-to-jul/src/main/resources/META-INF/services/org.apache.logging.log4j.spi.Provider b/log4j-to-jul/src/main/resources/META-INF/services/org.apache.logging.log4j.spi.Provider new file mode 100644 index 0000000..2ac36b5 --- /dev/null +++ b/log4j-to-jul/src/main/resources/META-INF/services/org.apache.logging.log4j.spi.Provider @@ -0,0 +1,18 @@ +# 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. + +org.apache.logging.log4j.tojul.JULProvider diff --git a/log4j-to-jul/src/site/markdown/index.md b/log4j-to-jul/src/site/markdown/index.md new file mode 100644 index 0000000..ffa5af5 --- /dev/null +++ b/log4j-to-jul/src/site/markdown/index.md @@ -0,0 +1,41 @@ + + + +# Log4j to JUL Adapter + +The Log4j 2 to JUL Adapter allows applications coded to the Log4j 2 API to be routed to `java.util.logging` (JUL). + +Use of this adapter may cause some loss of performance as the Log4j 2 Messages must be formatted +before they can be passed to JUL. With Log4j 2 as the implementation these would normally be +formatted only when they are accessed by a Filter or Appender. + +## Requirements + +The Log4j 2 to JUL adapter is dependent on the Log4j 2 API. +For more information, see [Runtime Dependencies](../runtime-dependencies.html). + +## Usage + +Include this JAR. Configure JUL as usual. + +
+Use of the JUL adapter (log4j-to-jul-2.x.jar) together with +the JUL bridge (log4j-jul-2.x.jar) should +never be attempted as it will cause events to endlessly be routed between +SLF4J and JUL. +
\ No newline at end of file diff --git a/log4j-to-jul/src/site/site.xml b/log4j-to-jul/src/site/site.xml new file mode 100644 index 0000000..6b84b63 --- /dev/null +++ b/log4j-to-jul/src/site/site.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java new file mode 100644 index 0000000..c418376 --- /dev/null +++ b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java @@ -0,0 +1,204 @@ +/* +* 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.log4j.tojul; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.google.common.testing.TestLogHandler; +import java.io.IOException; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import org.apache.logging.log4j.LogManager; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class LoggerTest { + + // Save levels so that we can reset them @After clearLogs() + private static final java.util.logging.Logger globalLogger = java.util.logging.Logger.getGlobal(); + private static final java.util.logging.Logger rootLogger = java.util.logging.Logger.getLogger(""); + private static final Level globalLevel = globalLogger.getLevel(); + private static final Level rootLevel = rootLogger.getLevel(); + + private org.apache.logging.log4j.Logger log4jLogger; + private java.util.logging.Logger julLogger; + private Level julLoggerDefaultLevel; + + // https://javadoc.io/doc/com.google.guava/guava-testlib/latest/com/google/common/testing/TestLogHandler.html + private TestLogHandler handler; + + + @Before public void setupLogCapture() { + handler = new TestLogHandler(); + // Beware, the order here should not be changed! + // Let the bridge do whatever it does BEFORE we create a JUL Logger (which SHOULD be the same) + log4jLogger = LogManager.getLogger(getClass()); + assertThat(log4jLogger).isInstanceOf(JULLogger.class); + julLogger = java.util.logging.Logger.getLogger(getClass().getName()); + assertThat(julLogger).isSameAs(((JULLogger)log4jLogger).getWrappedLogger()); + julLogger.addHandler(handler); + + julLoggerDefaultLevel = julLogger.getLevel(); + + // Check that there is no configuration file which invalidates our assumption that the root logger is the parent of our julLogger + assertThat(julLogger.getParent()).isEqualTo(rootLogger); + } + + @After public void clearLogs() { + julLogger.removeHandler(handler); + // Reset all Levels what any tests set anymore + julLogger.setLevel(julLoggerDefaultLevel); + rootLogger.setLevel(rootLevel); + globalLogger.setLevel(globalLevel); + } + + @Test public void infoAtInfo() { + julLogger.setLevel(Level.INFO); + log4jLogger.info("hello, world"); + + List logs = handler.getStoredLogRecords(); + assertThat(logs).hasSize(1); + LogRecord log1 = logs.get(0); + assertThat(log1.getLoggerName()).isEqualTo(getClass().getName()); + assertThat(log1.getLevel()).isEqualTo(java.util.logging.Level.INFO); + assertThat(log1.getMessage()).isEqualTo("hello, world"); + assertThat(log1.getParameters()).isNull(); + assertThat(log1.getThrown()).isNull(); + assertThat(log1.getSourceClassName()).isNull(); + assertThat(log1.getSourceMethodName()).isNull(); + } + + @Test public void infoAtInfoWithParameters() { + julLogger.setLevel(Level.INFO); + log4jLogger.info("hello, {}", "world"); + + List logs = handler.getStoredLogRecords(); + assertThat(logs).hasSize(1); + LogRecord log1 = logs.get(0); + assertThat(log1.getMessage()).isEqualTo("hello, world"); + assertThat(log1.getParameters()).isNull(); + assertThat(log1.getThrown()).isNull(); + } + + @Test public void errorAtSevereWithException() { + julLogger.setLevel(Level.SEVERE); + log4jLogger.error("hello, {}", "world", new IOException("Testing, testing")); + + List logs = handler.getStoredLogRecords(); + assertThat(logs).hasSize(1); + LogRecord log1 = logs.get(0); + assertThat(log1.getMessage()).isEqualTo("hello, world"); + assertThat(log1.getParameters()).isNull(); + assertThat(log1.getThrown()).isInstanceOf(IOException.class); + } + + @Test public void infoAtInfoWithLogBuilder() { + julLogger.setLevel(Level.INFO); + log4jLogger.atInfo().log("hello, world"); + assertThat(handler.getStoredLogRecords()).hasSize(1); + } + + @Test public void infoAtInfoOnParent() { + julLogger.getParent().setLevel(Level.INFO); + log4jLogger.info("hello, world"); + assertThat(handler.getStoredLogRecords()).hasSize(1); + } + + @Test public void infoWithoutAnyLevel() { + // We're not setting any level. + log4jLogger.info("hello, world"); + assertThat(handler.getStoredLogRecords()).hasSize(1); + } + + @Test public void debugAtInfo() { + julLogger.setLevel(Level.INFO); + log4jLogger.debug("hello, world"); + assertThat(handler.getStoredLogRecords()).isEmpty(); + } + + @Test public void debugAtFiner() { + julLogger.setLevel(Level.FINER); + log4jLogger.debug("hello, world"); + assertThat(handler.getStoredLogRecords()).hasSize(1); + } + + @Test public void traceAtFine() { + julLogger.setLevel(Level.FINE); + log4jLogger.trace("hello, world"); + assertThat(handler.getStoredLogRecords()).isEmpty(); + } + + @Test public void traceAtAllOnParent() { + julLogger.getParent().setLevel(Level.ALL); + log4jLogger.trace("hello, world"); + assertThat(handler.getStoredLogRecords()).hasSize(1); + } + + @Test public void fatalAtOff() { + julLogger.getParent().setLevel(Level.OFF); + log4jLogger.fatal("hello, world"); + assertThat(handler.getStoredLogRecords()).isEmpty(); + } + + @Test public void fatalAtSevere() { + julLogger.getParent().setLevel(Level.SEVERE); + log4jLogger.atFatal().log("hello, world"); + assertThat(handler.getStoredLogRecords()).hasSize(1); + } + + @Test public void warnAtFatal() { + julLogger.getParent().setLevel(Level.SEVERE); + log4jLogger.atWarn().log("hello, world"); + assertThat(handler.getStoredLogRecords()).isEmpty(); + } + + @Test public void customLevelJustUnderWarning() { + julLogger.getParent().setLevel(new CustomLevel("Just under Warning", Level.WARNING.intValue() - 1)); + + log4jLogger.info("hello, world"); + assertThat(handler.getStoredLogRecords()).isEmpty(); + + log4jLogger.warn("hello, world"); + assertThat(handler.getStoredLogRecords()).hasSize(1); + + log4jLogger.error("hello, world"); + assertThat(handler.getStoredLogRecords()).hasSize(2); + } + + @Test public void customLevelJustAboveWarning() { + julLogger.getParent().setLevel(new CustomLevel("Just above Warning", Level.WARNING.intValue() + 1)); + + log4jLogger.info("hello, world"); + assertThat(handler.getStoredLogRecords()).isEmpty(); + + log4jLogger.warn("hello, world"); + assertThat(handler.getStoredLogRecords()).isEmpty(); + + log4jLogger.error("hello, world"); + assertThat(handler.getStoredLogRecords()).hasSize(1); + } + + @SuppressWarnings("serial") + private static class CustomLevel extends Level { + CustomLevel(String name, int value) { + super(name, value); + } + } +} From 7e588d3ffc6098df2d8965cf4dd9a1a3c49643ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vorburger=20=E2=9B=91=EF=B8=8F?= Date: Sat, 15 Jan 2022 00:39:54 +0100 Subject: [PATCH 03/65] LOG4J2-3282 Support source class & method in to-jul (#698) --- .../apache/logging/log4j/tojul/JULLogger.java | 7 +- .../log4j/tojul/LazyLog4jLogRecord.java | 70 +++++++++++++++++++ .../logging/log4j/tojul/LoggerTest.java | 27 ++++++- 3 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java index 52c5299..5f27ae3 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java @@ -18,7 +18,6 @@ import static java.util.Objects.requireNonNull; -import java.util.logging.LogRecord; import java.util.logging.Logger; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Marker; @@ -60,15 +59,11 @@ public void logMessage(final String fqcn, final Level level, final Marker marker if (!logger.isLoggable(julLevel)) { return; } - LogRecord record = new LogRecord(julLevel, message.getFormattedMessage()); // NOT getFormat() + LazyLog4jLogRecord record = new LazyLog4jLogRecord(fqcn, julLevel, message.getFormattedMessage()); // NOT getFormat() // NOT record.setParameters(message.getParameters()); BECAUSE getFormattedMessage() NOT getFormat() record.setLoggerName(getName()); record.setThrown(t == null ? message.getThrowable() : t); - // Source class/method is not supported (yet) - record.setSourceClassName(null); - record.setSourceMethodName(null); logger.log(record); - // fqcn is un-used } // Convert Level in Log4j scale to JUL scale. diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java new file mode 100644 index 0000000..f7bce8f --- /dev/null +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java @@ -0,0 +1,70 @@ +/* + * 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.log4j.tojul; + +import java.util.logging.Level; +import java.util.logging.LogRecord; +import org.apache.logging.log4j.util.StackLocatorUtil; + +/** + * Extension of {@link java.util.logging.LogRecord} with lazy get source related methods based on Log4j's {@link StackLocatorUtil#calcLocation(String)}. + */ +final class LazyLog4jLogRecord extends LogRecord { + + private static final long serialVersionUID = 6798134264543826471L; + + // parent class LogRecord already has a needToInferCaller but it's private + private transient boolean inferCaller = true; + + private final String fqcn; + + LazyLog4jLogRecord(String fqcn, Level level, String msg) { + super(level, msg); + this.fqcn = fqcn; + } + + @Override + public String getSourceClassName() { + if (inferCaller) { + inferCaller(); + } + return super.getSourceClassName(); + } + + @Override + public String getSourceMethodName() { + if (inferCaller) { + inferCaller(); + } + return super.getSourceMethodName(); + } + + private void inferCaller() { + StackTraceElement location = null; + if (fqcn != null) { + location = StackLocatorUtil.calcLocation(fqcn); + } + if (location != null) { + setSourceClassName(location.getClassName()); + setSourceMethodName(location.getMethodName()); + } else { + setSourceClassName(null); + setSourceMethodName(null); + } + inferCaller = false; + } +} \ No newline at end of file diff --git a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java index c418376..aabc338 100644 --- a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java +++ b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java @@ -81,8 +81,8 @@ public class LoggerTest { assertThat(log1.getMessage()).isEqualTo("hello, world"); assertThat(log1.getParameters()).isNull(); assertThat(log1.getThrown()).isNull(); - assertThat(log1.getSourceClassName()).isNull(); - assertThat(log1.getSourceMethodName()).isNull(); + assertThat(log1.getSourceClassName()).isEqualTo(getClass().getName()); + assertThat(log1.getSourceMethodName()).isEqualTo("infoAtInfo"); } @Test public void infoAtInfoWithParameters() { @@ -201,4 +201,27 @@ private static class CustomLevel extends Level { super(name, value); } } + + /** + * Test that the {@link LogRecord#getSourceClassName()}, which we already tested above in infoAtInfo() + * also works as expected if the logging happened in a class that we have called (indirect), not in the test method itself. + */ + @Test public void indirectSource() { + java.util.logging.Logger.getLogger(Another.class.getName()).setLevel(Level.INFO); + new Another(handler); + List logs = handler.getStoredLogRecords(); + assertThat(logs).hasSize(1); + LogRecord log1 = logs.get(0); + assertThat(log1.getSourceClassName()).isEqualTo(Another.class.getName()); + assertThat(log1.getSourceMethodName()).isEqualTo(""); + } + + static class Another { + org.apache.logging.log4j.Logger anotherLog4jLogger = LogManager.getLogger(getClass()); + java.util.logging.Logger anotherJULLogger = java.util.logging.Logger.getLogger(getClass().getName()); + Another(TestLogHandler handler) { + anotherJULLogger.addHandler(handler); + anotherLog4jLogger.info("hello, another world"); + } + } } From ddd70249b1fc25abb480a1dc3f76c2f02d46fb46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vorburger=20=E2=9B=91=EF=B8=8F?= Date: Sat, 15 Jan 2022 00:49:15 +0100 Subject: [PATCH 04/65] Increase to-jul priority from 15 to 20 (#699) The original 15 was blindly copied from SLF4JProvider. It's probably better to not have them be the same, and have To-JUL's higher than SLF4j's (which in turn is higher than Core's 10). --- .../main/java/org/apache/logging/log4j/tojul/JULProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java index 2c57ef9..b460015 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java @@ -25,6 +25,6 @@ */ public class JULProvider extends Provider { public JULProvider() { - super(15, "2.6.0", JULLoggerContextFactory.class, null); + super(20, "2.6.0", JULLoggerContextFactory.class, null); } } From ae55d0f3821954c7e813d29e6e2391fedace63b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vorburger=20=E2=9B=91=EF=B8=8F?= Date: Sun, 16 Jan 2022 18:22:57 +0100 Subject: [PATCH 05/65] Add inceptionYear 2022 in to-jul POM (#702) --- log4j-to-jul/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 95c209e..e585ad2 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -27,6 +27,7 @@ jar Apache Log4j to JUL Bridge The Apache Log4j binding between Log4j 2 API and java.util.logging (JUL). + 2022 ${basedir}/.. Log4j to JUL Documentation From 10adb7023082d4c78fc1b4222df4cbad3cab7754 Mon Sep 17 00:00:00 2001 From: Carter Kozak Date: Mon, 17 Jan 2022 20:38:24 -0500 Subject: [PATCH 06/65] Additional log4j-to-jul test coverage for correct formatting (#712) These tests provide additional coverage in the event parameters are passed through, demonstrating how JUL formatters are likely to misinterpret such LogRecords. --- .../logging/log4j/tojul/LoggerTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java index aabc338..9849778 100644 --- a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java +++ b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java @@ -224,4 +224,26 @@ static class Another { anotherLog4jLogger.info("hello, another world"); } } + + @Test public void placeholdersInFormat() { + julLogger.setLevel(Level.INFO); + log4jLogger.info("hello, {0} {}", "world"); + + List logs = handler.getStoredLogRecords(); + assertThat(logs).hasSize(1); + LogRecord log1 = logs.get(0); + String formattedMessage = new java.util.logging.SimpleFormatter().formatMessage(log1); + assertThat(formattedMessage).isEqualTo("hello, {0} world"); + } + + @Test public void placeholdersInFormattedMessage() { + julLogger.setLevel(Level.INFO); + log4jLogger.info("hello, {}", "{0} world"); + + List logs = handler.getStoredLogRecords(); + assertThat(logs).hasSize(1); + LogRecord log1 = logs.get(0); + String formattedMessage = new java.util.logging.SimpleFormatter().formatMessage(log1); + assertThat(formattedMessage).isEqualTo("hello, {0} world"); + } } From 3d26b85376ecd38da39049369db86c8d29d338f9 Mon Sep 17 00:00:00 2001 From: Matt Sicker Date: Fri, 21 Jan 2022 21:39:48 -0600 Subject: [PATCH 07/65] Clean up pom.xml files - Remove invalid values - Disable doap and changes plugins in child modules - Use correct Fragment-Host in bundles implementing log4j-core plugins - Add OSGi service loader metadata for more bundles --- log4j-to-jul/pom.xml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index e585ad2..e6321f8 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -21,7 +21,6 @@ org.apache.logging.log4j log4j 2.17.2-SNAPSHOT - ../ log4j-to-jul jar @@ -81,7 +80,13 @@ maven-bundle-plugin - org.apache.logging.tojul + org.apache.logging.log4j.tojul + + osgi.extender;filter:="(osgi.extender=osgi.serviceloader.registrar)" + + + osgi.serviceloader;osgi.serviceloader=org.apache.logging.log4j.spi.Provider + From 6f2e06f1d58f131ea36f0cdb28dd7e881fc4e74d Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Wed, 23 Feb 2022 00:33:12 -0700 Subject: [PATCH 08/65] Some of the necessary revapi changes --- log4j-to-jul/pom.xml | 1 + log4j-to-jul/revapi.json | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 log4j-to-jul/revapi.json diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index e6321f8..3189630 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -33,6 +33,7 @@ /log4j-to-jul org.apache.logging.tojul true + true diff --git a/log4j-to-jul/revapi.json b/log4j-to-jul/revapi.json new file mode 100644 index 0000000..f7d03f6 --- /dev/null +++ b/log4j-to-jul/revapi.json @@ -0,0 +1,12 @@ +[ + { + "extension": "revapi.filter", + "configuration": { + "elements": { + "exclude": [ + "class org\\.apache\\.logging\\.log4j\\.spi\\.LoggerContext", + ] + } + } + } +] \ No newline at end of file From 82a2c79ceeaba1d76913607e151d59ebb619c029 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Wed, 23 Feb 2022 13:27:21 -0700 Subject: [PATCH 09/65] [maven-release-plugin] prepare release log4j-2.17.2-rc1 --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 3189630..1ced4a5 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.17.2-SNAPSHOT + 2.17.2 log4j-to-jul jar From d4625910a19cd4f2b2482dff9143bf2aa3ce39da Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Wed, 23 Feb 2022 13:27:33 -0700 Subject: [PATCH 10/65] [maven-release-plugin] prepare for next development iteration --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 1ced4a5..cf57f2e 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.17.2 + 2.17.3-SNAPSHOT log4j-to-jul jar From 97d4c24178faa9159fa66dd28119e85940636808 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Tue, 28 Jun 2022 15:02:52 -0700 Subject: [PATCH 11/65] [maven-release-plugin] prepare release log4j-2.18.0-rc1 --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index cf57f2e..edc4609 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.17.3-SNAPSHOT + 2.18.0 log4j-to-jul jar From 2d940003e244bf077a5d22bc303e0b9bf30d9206 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Tue, 28 Jun 2022 15:03:03 -0700 Subject: [PATCH 12/65] [maven-release-plugin] prepare for next development iteration --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index edc4609..756d5a1 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.18.0 + 2.18.1-SNAPSHOT log4j-to-jul jar From 0bf8e3d75f81456e3f828bd1595a59472a7ead22 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Sun, 3 Jul 2022 21:04:11 +0200 Subject: [PATCH 13/65] [LOG4J2-3546] Switch from `osgi.serviceloader` to `Activator` Switches `log4j-to-slf4j` and `log4j-to-jul` from using the Service Loader Mediator to registering their provider themselves. This way they can be used in minimal OSGI systems. Newer tests in `log4j-osgi` are written using PAX Exam in order to provide a larger OSGI environment. --- log4j-to-jul/pom.xml | 11 ++++---- .../apache/logging/log4j/tojul/Activator.java | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 756d5a1..661831e 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -40,6 +40,10 @@ org.apache.logging.log4j log4j-api + + org.osgi + org.osgi.core + com.google.guava guava-testlib @@ -81,13 +85,8 @@ maven-bundle-plugin + org.apache.logging.log4j.tojul.Activator org.apache.logging.log4j.tojul - - osgi.extender;filter:="(osgi.extender=osgi.serviceloader.registrar)" - - - osgi.serviceloader;osgi.serviceloader=org.apache.logging.log4j.spi.Provider - diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java new file mode 100644 index 0000000..47cc1f3 --- /dev/null +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java @@ -0,0 +1,26 @@ +/* + * 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.log4j.tojul; + +import org.apache.logging.log4j.util.ProviderActivator; + +public class Activator extends ProviderActivator { + + public Activator() { + super(new JULProvider()); + } +} From ab33e0c742891a7da704e10a9ce47db02e1e61bd Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Thu, 28 Jul 2022 22:21:53 +0200 Subject: [PATCH 14/65] [LOG4J2-3564] Fix NPE when root logger level is null `LogManager.getGlobal().getLevel()` is not a good fallback for the case when all JUL logger levels are null, since its level is usually null. --- .../apache/logging/log4j/tojul/JULLogger.java | 3 +- .../logging/log4j/tojul/JULLoggerTest.java | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java index 5f27ae3..1a67ea3 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java @@ -153,7 +153,8 @@ private java.util.logging.Level getEffectiveJULLevel() { return current.getLevel(); } // This is a safety fallback that is typically never reached, because usually the root Logger.getLogger("") has a Level. - return Logger.getGlobal().getLevel(); + // Since JDK 8 the LogManager$RootLogger does not have a default level, just a default effective level of INFO. + return java.util.logging.Level.INFO; } private boolean isEnabledFor(final Level level, final Marker marker) { diff --git a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java new file mode 100644 index 0000000..1bd2742 --- /dev/null +++ b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java @@ -0,0 +1,35 @@ +/* + * 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.log4j.tojul; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.apache.logging.log4j.Level; +import org.junit.jupiter.api.Test; + +public class JULLoggerTest { + + @Test + public void testNotNullEffectiveLevel() { + // Emulates the root logger found in Tomcat, with a null level + // See: https://bz.apache.org/bugzilla/show_bug.cgi?id=66184 + final java.util.logging.Logger julLogger = new java.util.logging.Logger("", null) { + }; + final JULLogger logger = new JULLogger("", julLogger); + assertEquals(Level.INFO, logger.getLevel()); + } +} From 43ed2636a1888a6ca9322077ebcd61b9cff48f13 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Tue, 6 Sep 2022 14:37:30 +0200 Subject: [PATCH 15/65] Use `junit-bom` This replaces independent JUnit5 dependency versioning with a single `junit-bom` dependency. --- log4j-to-jul/pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 661831e..19739c7 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -52,10 +52,12 @@ org.junit.vintage junit-vintage-engine + test org.junit.jupiter junit-jupiter-engine + test org.assertj From 90670a78ec2e4d813905481d54619d1dd6ddd4f0 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Fri, 9 Sep 2022 00:18:17 -0700 Subject: [PATCH 16/65] [maven-release-plugin] prepare release log4j-2.19.0-rc1 --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 19739c7..0cf1ba7 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.18.1-SNAPSHOT + 2.19.0 log4j-to-jul jar From dcfb1a07caa48ce31ffea6374ea574252e4bde0c Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Fri, 9 Sep 2022 00:18:29 -0700 Subject: [PATCH 17/65] [maven-release-plugin] prepare for next development iteration --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 0cf1ba7..97062f6 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.19.0 + 2.19.1-SNAPSHOT log4j-to-jul jar From 0063ec4eda7fe39827603d50abedfab88bd4a53c Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Fri, 9 Sep 2022 12:24:00 -0700 Subject: [PATCH 18/65] [maven-release-plugin] prepare release log4j-2.19.0-rc1 --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 97062f6..0cf1ba7 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.19.1-SNAPSHOT + 2.19.0 log4j-to-jul jar From dbd3c554098a7f79fef4f2682ef2846400d1f51a Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Fri, 9 Sep 2022 12:24:11 -0700 Subject: [PATCH 19/65] [maven-release-plugin] prepare for next development iteration --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 0cf1ba7..97062f6 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.19.0 + 2.19.1-SNAPSHOT log4j-to-jul jar From fdcd7b7dffd14d944c1d6b967a92522eca0d2684 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Tue, 13 Sep 2022 10:15:41 -0700 Subject: [PATCH 20/65] [maven-release-plugin] prepare release log4j-2.19.0-rc2 --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 97062f6..0cf1ba7 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.19.1-SNAPSHOT + 2.19.0 log4j-to-jul jar From 2ec88ac712ad9f912398afe7534ea2f65ce9441d Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Tue, 13 Sep 2022 10:15:54 -0700 Subject: [PATCH 21/65] [maven-release-plugin] prepare for next development iteration --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 0cf1ba7..28c0ec2 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.19.0 + 2.29.1-SNAPSHOT log4j-to-jul jar From e8dc8ba97895fa3c7a8760d57d555a0d28b87bb7 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Sat, 17 Sep 2022 00:53:47 +0200 Subject: [PATCH 22/65] Fix new snapshot version --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 28c0ec2..97062f6 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.29.1-SNAPSHOT + 2.19.1-SNAPSHOT log4j-to-jul jar From caba4d37753cfb9ab4a2c98fad8ff792926eb259 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Fri, 16 Sep 2022 11:18:23 +0200 Subject: [PATCH 23/65] Add scopes to child POM dependencies This removes the scope of the dependencies from and adds it to the children POMs. The reason behind this is that we don't want to force the scope of transitive dependencies: e.g. `log4j-api` has a `javax.inject` transitive test dependency. If we set the scope to `provided` in the parent POM, the test dependency becomes a provided dependency. --- log4j-to-jul/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 97062f6..3500e8c 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -43,6 +43,7 @@ org.osgi org.osgi.core + provided com.google.guava From 376d098bb4e908a14aebc505cc44d59ecce619dd Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Sun, 18 Sep 2022 20:24:48 +0200 Subject: [PATCH 24/65] Sort dependencies in POMs Improves the `src/tools/sort-pom.xslt` stylesheet to sort dependencies in the POM files according to the scope, artifact id (with a priority for Logj2 artifacts) and group id. It uses this script to automatically sort all POM files. --- log4j-to-jul/pom.xml | 52 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 3500e8c..6d50c25 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -36,23 +36,23 @@ true - - org.apache.logging.log4j - log4j-api - org.osgi org.osgi.core provided - com.google.guava - guava-testlib + org.apache.logging.log4j + log4j-api + + + org.assertj + assertj-core test - org.junit.vintage - junit-vintage-engine + com.google.guava + guava-testlib test @@ -61,13 +61,23 @@ test - org.assertj - assertj-core + org.junit.vintage + junit-vintage-engine test + + org.apache.felix + maven-bundle-plugin + + + org.apache.logging.log4j.tojul.Activator + org.apache.logging.log4j.tojul + + + org.apache.maven.plugins @@ -83,16 +93,6 @@ - - org.apache.felix - maven-bundle-plugin - - - org.apache.logging.log4j.tojul.Activator - org.apache.logging.log4j.tojul - - - @@ -131,9 +131,9 @@ maven-javadoc-plugin ${javadoc.plugin.version} - Copyright © {inceptionYear}-{currentYear} {organizationName}. All Rights Reserved.
+ <p align="center">Copyright &#169; {inceptionYear}-{currentYear} {organizationName}. All Rights Reserved.<br /> Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, - and the Apache Log4j logo are trademarks of The Apache Software Foundation.

]]>
+ and the Apache Log4j logo are trademarks of The Apache Software Foundation.</p>
false @@ -148,10 +148,6 @@ - - com.github.spotbugs - spotbugs-maven-plugin - org.apache.maven.plugins maven-jxr-plugin @@ -179,6 +175,10 @@ ${maven.compiler.target}
+ + com.github.spotbugs + spotbugs-maven-plugin +
From 6f4893c5badc95b65ce3cd4abad1b05b4fd9a41d Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Sun, 18 Sep 2022 10:53:36 +0200 Subject: [PATCH 25/65] Delegates plugin versions to ASF parent This PR removes all explicitly versioned plugins that are also defined in the Apache ASF parent POM (`org.apache:apache`). This has the following effect on plugin versions: * `maven-assembly-plugin` bumped to 3.4.1 * `maven-jar-plugin` bumped to 3.2.2 * `maven-javadoc-plugin` bumped to 3.4.0 * `maven-project-info-reports-plugin` bumped to 3.3.0 * `maven-release-plugin` bumped to 3.0.0-M6 * `maven-scm-plugin` bumped to 1.13.0 * `maven-site-plugin` bumped to 3.12.0 --- log4j-to-jul/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 6d50c25..e5c689c 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -129,7 +129,6 @@ org.apache.maven.plugins maven-javadoc-plugin - ${javadoc.plugin.version} <p align="center">Copyright &#169; {inceptionYear}-{currentYear} {organizationName}. All Rights Reserved.<br /> Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, From b34c41754f89f6a0b31e08a8a5c7071076bb4221 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Sun, 2 Oct 2022 08:32:58 +0200 Subject: [PATCH 26/65] Centralize plugin versions in main POM The versions of all used plugins are specified in the `log4j` parent POM or other parent POMs (`log4j-bom`, `log4j-samples`, `log4j-spring-cloud-config` or `log4j-spring-cloud-config-samples`). The script `src/tools/explicit-version.xslt` can be used to check for explicitly provided version. --- log4j-to-jul/pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index e5c689c..33d45d3 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -100,7 +100,6 @@ org.apache.maven.plugins maven-changes-plugin - ${changes.plugin.version} @@ -116,7 +115,6 @@ org.apache.maven.plugins maven-checkstyle-plugin - ${checkstyle.plugin.version} ${log4jParentDir}/checkstyle.xml @@ -150,7 +148,6 @@ org.apache.maven.plugins maven-jxr-plugin - ${jxr.plugin.version} non-aggregate @@ -169,7 +166,6 @@ org.apache.maven.plugins maven-pmd-plugin - ${pmd.plugin.version} ${maven.compiler.target} From 79e9e4ac66d3c8f20aecb0e0a99cd2c1ec503dd0 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Tue, 18 Oct 2022 11:01:39 +0200 Subject: [PATCH 27/65] Remove no-op plugin execution The 'default' maven-remote-resources-plugin execution is a no-op, because the ASF parent uses a different id. --- log4j-to-jul/pom.xml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 33d45d3..fd30ea0 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -78,21 +78,6 @@ - - - org.apache.maven.plugins - maven-remote-resources-plugin - - - - process - - - false - - - - From 66ebed486c8ae718d8ce3f6ea154cfe8cbd85d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20Yaz=C4=B1c=C4=B1?= Date: Fri, 13 Jan 2023 17:14:26 +0100 Subject: [PATCH 28/65] LOG4J2-3628 Replace `maven-changes-plugin` with `log4j-changelog` (#1145) --- log4j-to-jul/pom.xml | 15 --------------- log4j-to-jul/src/site/site.xml | 2 -- 2 files changed, 17 deletions(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index fd30ea0..c9723da 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -82,21 +82,6 @@ - - org.apache.maven.plugins - maven-changes-plugin - - - - changes-report - - - - - %URL%/show_bug.cgi?id=%ISSUE% - true - - org.apache.maven.plugins maven-checkstyle-plugin diff --git a/log4j-to-jul/src/site/site.xml b/log4j-to-jul/src/site/site.xml index 6b84b63..c7f15e5 100644 --- a/log4j-to-jul/src/site/site.xml +++ b/log4j-to-jul/src/site/site.xml @@ -43,8 +43,6 @@
- - From 1872837a4882417ef2d87208d1054ad579598e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20Yaz=C4=B1c=C4=B1?= Date: Mon, 16 Jan 2023 19:37:49 +0100 Subject: [PATCH 29/65] Simplify site generation (#1166) --- log4j-to-jul/pom.xml | 1 - log4j-to-jul/src/site/markdown/index.md | 41 -------------------- log4j-to-jul/src/site/site.xml | 50 ------------------------- 3 files changed, 92 deletions(-) delete mode 100644 log4j-to-jul/src/site/markdown/index.md delete mode 100644 log4j-to-jul/src/site/site.xml diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index c9723da..3d79a88 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -32,7 +32,6 @@ Log4j to JUL Documentation /log4j-to-jul org.apache.logging.tojul - true true diff --git a/log4j-to-jul/src/site/markdown/index.md b/log4j-to-jul/src/site/markdown/index.md deleted file mode 100644 index ffa5af5..0000000 --- a/log4j-to-jul/src/site/markdown/index.md +++ /dev/null @@ -1,41 +0,0 @@ - - - -# Log4j to JUL Adapter - -The Log4j 2 to JUL Adapter allows applications coded to the Log4j 2 API to be routed to `java.util.logging` (JUL). - -Use of this adapter may cause some loss of performance as the Log4j 2 Messages must be formatted -before they can be passed to JUL. With Log4j 2 as the implementation these would normally be -formatted only when they are accessed by a Filter or Appender. - -## Requirements - -The Log4j 2 to JUL adapter is dependent on the Log4j 2 API. -For more information, see [Runtime Dependencies](../runtime-dependencies.html). - -## Usage - -Include this JAR. Configure JUL as usual. - -
-Use of the JUL adapter (log4j-to-jul-2.x.jar) together with -the JUL bridge (log4j-jul-2.x.jar) should -never be attempted as it will cause events to endlessly be routed between -SLF4J and JUL. -
\ No newline at end of file diff --git a/log4j-to-jul/src/site/site.xml b/log4j-to-jul/src/site/site.xml deleted file mode 100644 index c7f15e5..0000000 --- a/log4j-to-jul/src/site/site.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 9e3b6b4aed55c252f6b1e549c81b2663a7eb9366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20Yaz=C4=B1c=C4=B1?= Date: Sun, 12 Feb 2023 21:53:05 +0100 Subject: [PATCH 30/65] Fix Javadoc generation and links for the site - Removed `maven-jxr-plugin` - Generating no Javadoc JARs (this was already the case) - Removed Javadoc JARs from the assembly in `log4j-distribution` - Generating Javadoc HTML only for `log4j-core` and `log4j-api` - Copying generated Javadoc HTML to `target/site/javadoc/` --- log4j-to-jul/pom.xml | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 3d79a88..e32e0d3 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -93,45 +93,6 @@ licensedir=${log4jParentDir}/checkstyle-header.txt - - org.apache.maven.plugins - maven-javadoc-plugin - - <p align="center">Copyright &#169; {inceptionYear}-{currentYear} {organizationName}. All Rights Reserved.<br /> - Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, - and the Apache Log4j logo are trademarks of The Apache Software Foundation.</p> - - false - true - - - - non-aggregate - - javadoc - - - - - - org.apache.maven.plugins - maven-jxr-plugin - - - non-aggregate - - jxr - - - - aggregate - - aggregate - - - - org.apache.maven.plugins maven-pmd-plugin From 042791ccc01b99bff39b7b943657a27f05336d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20Yaz=C4=B1c=C4=B1?= Date: Sun, 12 Feb 2023 22:10:19 +0100 Subject: [PATCH 31/65] Remove `revapi` leftovers --- log4j-to-jul/pom.xml | 1 - log4j-to-jul/revapi.json | 12 ------------ 2 files changed, 13 deletions(-) delete mode 100644 log4j-to-jul/revapi.json diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index e32e0d3..1a6ce6f 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -32,7 +32,6 @@ Log4j to JUL Documentation /log4j-to-jul org.apache.logging.tojul - true diff --git a/log4j-to-jul/revapi.json b/log4j-to-jul/revapi.json deleted file mode 100644 index f7d03f6..0000000 --- a/log4j-to-jul/revapi.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "extension": "revapi.filter", - "configuration": { - "elements": { - "exclude": [ - "class org\\.apache\\.logging\\.log4j\\.spi\\.LoggerContext", - ] - } - } - } -] \ No newline at end of file From 3149f6440703e54476bfbe57b901fb9dacd61a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20Yaz=C4=B1c=C4=B1?= Date: Tue, 14 Feb 2023 21:10:18 +0100 Subject: [PATCH 32/65] Remove Maven `` blocks, since reporting is disabled --- log4j-to-jul/pom.xml | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 1a6ce6f..931eaed 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -78,31 +78,4 @@ - - - - org.apache.maven.plugins - maven-checkstyle-plugin - - - ${log4jParentDir}/checkstyle.xml - ${log4jParentDir}/checkstyle-suppressions.xml - false - basedir=${basedir} - licensedir=${log4jParentDir}/checkstyle-header.txt - - - - org.apache.maven.plugins - maven-pmd-plugin - - ${maven.compiler.target} - - - - com.github.spotbugs - spotbugs-maven-plugin - - - From 2fc77e6d288cd0da3e9d052171d1df43012cc2d8 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Fri, 17 Feb 2023 18:26:33 -0700 Subject: [PATCH 33/65] [maven-release-plugin] prepare release log4j-2.20.1-rc1 --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 931eaed..7100b2f 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.19.1-SNAPSHOT + 2.20.0 log4j-to-jul jar From 976955cf0eb578faa31af3a005d561ee7be8bae6 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Fri, 17 Feb 2023 18:26:37 -0700 Subject: [PATCH 34/65] [maven-release-plugin] prepare for next development iteration --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 7100b2f..b5a2b98 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.20.0 + 2.20.1-SNAPSHOT log4j-to-jul jar From 95164d1601f5b8a3a3539b23fa02eec722778c20 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Fri, 17 Feb 2023 21:40:16 -0700 Subject: [PATCH 35/65] [maven-release-plugin] prepare release log4j-2.20.1-rc1 --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index b5a2b98..7100b2f 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.20.1-SNAPSHOT + 2.20.0 log4j-to-jul jar From 60d92f3a5693772e584556e884b4d4a8dd733eb7 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Fri, 17 Feb 2023 21:48:49 -0700 Subject: [PATCH 36/65] Revert version update --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 7100b2f..931eaed 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.20.0 + 2.19.1-SNAPSHOT log4j-to-jul jar From 9f548c3d5b4054d6fac15a30d1f9c27bd66f0727 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Fri, 17 Feb 2023 21:54:33 -0700 Subject: [PATCH 37/65] [maven-release-plugin] prepare release log4j-2.20.0-rc1 --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 931eaed..7100b2f 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.19.1-SNAPSHOT + 2.20.0 log4j-to-jul jar From b0ca80c9f038e0d0115b8aa80c734d94e35465a0 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Fri, 17 Feb 2023 21:54:36 -0700 Subject: [PATCH 38/65] [maven-release-plugin] prepare for next development iteration --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 7100b2f..b5a2b98 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.20.0 + 2.20.1-SNAPSHOT log4j-to-jul jar From bec4cf2acf2c82cc6642ce5962da604b8888dbfd Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Fri, 17 Feb 2023 22:00:23 -0700 Subject: [PATCH 39/65] [maven-release-plugin] rollback the release of log4j-2.20.0-rc1 --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index b5a2b98..931eaed 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.20.1-SNAPSHOT + 2.19.1-SNAPSHOT log4j-to-jul jar From a3d3c2af529edb089c2f77425558b15ebe446ecb Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Fri, 17 Feb 2023 22:19:34 -0700 Subject: [PATCH 40/65] [maven-release-plugin] prepare release log4j-2.20.0-rc1 --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 931eaed..7100b2f 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.19.1-SNAPSHOT + 2.20.0 log4j-to-jul jar From c0560851ddbe413c2e70c4ab6209e9cd4cfe7018 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Fri, 17 Feb 2023 22:19:38 -0700 Subject: [PATCH 41/65] [maven-release-plugin] prepare for next development iteration --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 7100b2f..b5a2b98 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.20.0 + 2.20.1-SNAPSHOT log4j-to-jul jar From 4953e551cbec3866b611ce8638e251df19ecfeea Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Wed, 29 Mar 2023 17:58:11 +0200 Subject: [PATCH 42/65] Renormalize Java file line endings This also runs `spotless:apply` on the modified files. --- .../logging/log4j/tojul/JULLoggerTest.java | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java index 1bd2742..629f91b 100644 --- a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java +++ b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java @@ -1,35 +1,35 @@ -/* - * 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.log4j.tojul; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.apache.logging.log4j.Level; -import org.junit.jupiter.api.Test; - -public class JULLoggerTest { - - @Test - public void testNotNullEffectiveLevel() { - // Emulates the root logger found in Tomcat, with a null level - // See: https://bz.apache.org/bugzilla/show_bug.cgi?id=66184 - final java.util.logging.Logger julLogger = new java.util.logging.Logger("", null) { - }; - final JULLogger logger = new JULLogger("", julLogger); - assertEquals(Level.INFO, logger.getLevel()); - } -} +/* + * 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.log4j.tojul; + +import org.apache.logging.log4j.Level; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class JULLoggerTest { + + @Test + public void testNotNullEffectiveLevel() { + // Emulates the root logger found in Tomcat, with a null level + // See: https://bz.apache.org/bugzilla/show_bug.cgi?id=66184 + final java.util.logging.Logger julLogger = new java.util.logging.Logger("", null) { + }; + final JULLogger logger = new JULLogger("", julLogger); + assertEquals(Level.INFO, logger.getLevel()); + } +} From 11bffc180c39b348c727e1cfd3dae8461a4529dd Mon Sep 17 00:00:00 2001 From: "spotless[bot]" Date: Tue, 25 Apr 2023 18:32:35 +0200 Subject: [PATCH 43/65] Apply Spotless to all files --- log4j-to-jul/pom.xml | 30 +++++++-------- .../apache/logging/log4j/tojul/Activator.java | 10 ++--- .../apache/logging/log4j/tojul/JULLogger.java | 15 ++++---- .../logging/log4j/tojul/JULLoggerContext.java | 11 +++--- .../log4j/tojul/JULLoggerContextFactory.java | 11 +++--- .../logging/log4j/tojul/JULProvider.java | 10 ++--- .../log4j/tojul/LazyLog4jLogRecord.java | 13 ++++--- .../logging/log4j/tojul/JULLoggerTest.java | 10 ++--- .../logging/log4j/tojul/LoggerTest.java | 38 +++++++++---------- 9 files changed, 76 insertions(+), 72 deletions(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index b5a2b98..c377d92 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -1,20 +1,20 @@ + ~ 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. + --> 4.0.0 diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java index 47cc1f3..5dee7ad 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with + * 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 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 + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.logging.log4j.tojul; diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java index 1a67ea3..baae5f1 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java @@ -1,30 +1,31 @@ /* * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with + * 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 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 + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.logging.log4j.tojul; -import static java.util.Objects.requireNonNull; - import java.util.logging.Logger; + import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.message.MessageFactory; import org.apache.logging.log4j.spi.AbstractLogger; +import static java.util.Objects.requireNonNull; + /** * Implementation of {@link org.apache.logging.log4j.Logger} that's backed by a {@link Logger}. * diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java index 4dca60e..fe8f3ef 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java @@ -1,22 +1,23 @@ /* * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with + * 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 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 + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.logging.log4j.tojul; import java.util.logging.Logger; + import org.apache.logging.log4j.message.MessageFactory; import org.apache.logging.log4j.spi.ExtendedLogger; import org.apache.logging.log4j.spi.LoggerContext; diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContextFactory.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContextFactory.java index f44a0d4..2a848f5 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContextFactory.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContextFactory.java @@ -1,22 +1,23 @@ /* * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with + * 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 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 + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.logging.log4j.tojul; import java.net.URI; + import org.apache.logging.log4j.spi.LoggerContext; import org.apache.logging.log4j.spi.LoggerContextFactory; import org.apache.logging.log4j.status.StatusLogger; diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java index b460015..27c2eca 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with + * 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 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 + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.logging.log4j.tojul; diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java index f7bce8f..b9b7c65 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java @@ -1,23 +1,24 @@ /* * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with + * 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 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 + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.logging.log4j.tojul; import java.util.logging.Level; import java.util.logging.LogRecord; + import org.apache.logging.log4j.util.StackLocatorUtil; /** @@ -67,4 +68,4 @@ private void inferCaller() { } inferCaller = false; } -} \ No newline at end of file +} diff --git a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java index 629f91b..3b3aa28 100644 --- a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java +++ b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with + * 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 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 + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.logging.log4j.tojul; diff --git a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java index 9849778..91977d9 100644 --- a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java +++ b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java @@ -1,34 +1,34 @@ /* -* 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. -*/ - + * 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.log4j.tojul; -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.common.testing.TestLogHandler; import java.io.IOException; import java.util.List; import java.util.logging.Level; import java.util.logging.LogRecord; + +import com.google.common.testing.TestLogHandler; import org.apache.logging.log4j.LogManager; import org.junit.After; import org.junit.Before; import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class LoggerTest { // Save levels so that we can reset them @After clearLogs() From 41fa3ae5606242b029ec8d2234cc7f75db1f7789 Mon Sep 17 00:00:00 2001 From: OpenRewrite Date: Sun, 4 Jun 2023 13:58:36 +0200 Subject: [PATCH 44/65] Use `final` whenever possible --- .../apache/logging/log4j/tojul/JULLogger.java | 6 ++-- .../log4j/tojul/LazyLog4jLogRecord.java | 2 +- .../logging/log4j/tojul/LoggerTest.java | 32 +++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java index baae5f1..cbd8f53 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java @@ -56,11 +56,11 @@ public Logger getWrappedLogger() { @Override public void logMessage(final String fqcn, final Level level, final Marker marker, final Message message, final Throwable t) { - java.util.logging.Level julLevel = convertLevel(level); + final java.util.logging.Level julLevel = convertLevel(level); if (!logger.isLoggable(julLevel)) { return; } - LazyLog4jLogRecord record = new LazyLog4jLogRecord(fqcn, julLevel, message.getFormattedMessage()); // NOT getFormat() + final LazyLog4jLogRecord record = new LazyLog4jLogRecord(fqcn, julLevel, message.getFormattedMessage()); // NOT getFormat() // NOT record.setParameters(message.getParameters()); BECAUSE getFormattedMessage() NOT getFormat() record.setLoggerName(getName()); record.setThrown(t == null ? message.getThrowable() : t); @@ -121,7 +121,7 @@ private java.util.logging.Level convertLevel(final Level level) { */ @Override public Level getLevel() { - int julLevel = getEffectiveJULLevel().intValue(); + final int julLevel = getEffectiveJULLevel().intValue(); // Test in logical order of likely frequency of use // Must be kept in sync with #convertLevel() if (julLevel == java.util.logging.Level.ALL.intValue()) { diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java index b9b7c65..b4d8fb5 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java @@ -33,7 +33,7 @@ final class LazyLog4jLogRecord extends LogRecord { private final String fqcn; - LazyLog4jLogRecord(String fqcn, Level level, String msg) { + LazyLog4jLogRecord(final String fqcn, final Level level, final String msg) { super(level, msg); this.fqcn = fqcn; } diff --git a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java index 91977d9..a028826 100644 --- a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java +++ b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java @@ -73,9 +73,9 @@ public class LoggerTest { julLogger.setLevel(Level.INFO); log4jLogger.info("hello, world"); - List logs = handler.getStoredLogRecords(); + final List logs = handler.getStoredLogRecords(); assertThat(logs).hasSize(1); - LogRecord log1 = logs.get(0); + final LogRecord log1 = logs.get(0); assertThat(log1.getLoggerName()).isEqualTo(getClass().getName()); assertThat(log1.getLevel()).isEqualTo(java.util.logging.Level.INFO); assertThat(log1.getMessage()).isEqualTo("hello, world"); @@ -89,9 +89,9 @@ public class LoggerTest { julLogger.setLevel(Level.INFO); log4jLogger.info("hello, {}", "world"); - List logs = handler.getStoredLogRecords(); + final List logs = handler.getStoredLogRecords(); assertThat(logs).hasSize(1); - LogRecord log1 = logs.get(0); + final LogRecord log1 = logs.get(0); assertThat(log1.getMessage()).isEqualTo("hello, world"); assertThat(log1.getParameters()).isNull(); assertThat(log1.getThrown()).isNull(); @@ -101,9 +101,9 @@ public class LoggerTest { julLogger.setLevel(Level.SEVERE); log4jLogger.error("hello, {}", "world", new IOException("Testing, testing")); - List logs = handler.getStoredLogRecords(); + final List logs = handler.getStoredLogRecords(); assertThat(logs).hasSize(1); - LogRecord log1 = logs.get(0); + final LogRecord log1 = logs.get(0); assertThat(log1.getMessage()).isEqualTo("hello, world"); assertThat(log1.getParameters()).isNull(); assertThat(log1.getThrown()).isInstanceOf(IOException.class); @@ -197,7 +197,7 @@ public class LoggerTest { @SuppressWarnings("serial") private static class CustomLevel extends Level { - CustomLevel(String name, int value) { + CustomLevel(final String name, final int value) { super(name, value); } } @@ -209,9 +209,9 @@ private static class CustomLevel extends Level { @Test public void indirectSource() { java.util.logging.Logger.getLogger(Another.class.getName()).setLevel(Level.INFO); new Another(handler); - List logs = handler.getStoredLogRecords(); + final List logs = handler.getStoredLogRecords(); assertThat(logs).hasSize(1); - LogRecord log1 = logs.get(0); + final LogRecord log1 = logs.get(0); assertThat(log1.getSourceClassName()).isEqualTo(Another.class.getName()); assertThat(log1.getSourceMethodName()).isEqualTo(""); } @@ -219,7 +219,7 @@ private static class CustomLevel extends Level { static class Another { org.apache.logging.log4j.Logger anotherLog4jLogger = LogManager.getLogger(getClass()); java.util.logging.Logger anotherJULLogger = java.util.logging.Logger.getLogger(getClass().getName()); - Another(TestLogHandler handler) { + Another(final TestLogHandler handler) { anotherJULLogger.addHandler(handler); anotherLog4jLogger.info("hello, another world"); } @@ -229,10 +229,10 @@ static class Another { julLogger.setLevel(Level.INFO); log4jLogger.info("hello, {0} {}", "world"); - List logs = handler.getStoredLogRecords(); + final List logs = handler.getStoredLogRecords(); assertThat(logs).hasSize(1); - LogRecord log1 = logs.get(0); - String formattedMessage = new java.util.logging.SimpleFormatter().formatMessage(log1); + final LogRecord log1 = logs.get(0); + final String formattedMessage = new java.util.logging.SimpleFormatter().formatMessage(log1); assertThat(formattedMessage).isEqualTo("hello, {0} world"); } @@ -240,10 +240,10 @@ static class Another { julLogger.setLevel(Level.INFO); log4jLogger.info("hello, {}", "{0} world"); - List logs = handler.getStoredLogRecords(); + final List logs = handler.getStoredLogRecords(); assertThat(logs).hasSize(1); - LogRecord log1 = logs.get(0); - String formattedMessage = new java.util.logging.SimpleFormatter().formatMessage(log1); + final LogRecord log1 = logs.get(0); + final String formattedMessage = new java.util.logging.SimpleFormatter().formatMessage(log1); assertThat(formattedMessage).isEqualTo("hello, {0} world"); } } From 07cf214156425d57b6e15ca40c30b65c2de7cc88 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Wed, 20 Sep 2023 09:04:34 +0200 Subject: [PATCH 45/65] Bump version to 2.21.0-SNAPSHOT --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index c377d92..8737200 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.20.1-SNAPSHOT + 2.21.0-SNAPSHOT log4j-to-jul jar From feb7b268230907aa6cfc129f3c10d176912fad96 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Mon, 25 Sep 2023 10:57:24 +0200 Subject: [PATCH 46/65] Remove references to `maven-bundle-plugin` --- log4j-to-jul/pom.xml | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 8737200..69afcd2 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -64,18 +64,5 @@ test - - - - org.apache.felix - maven-bundle-plugin - - - org.apache.logging.log4j.tojul.Activator - org.apache.logging.log4j.tojul - - - - - + From 13fc4b877df80b7e6f0df2e5c994ecdc6cb7ce91 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Tue, 26 Sep 2023 09:03:51 +0200 Subject: [PATCH 47/65] Replace explicit versions with property --- log4j-to-jul/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 69afcd2..cd1bdc5 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -20,7 +20,7 @@ org.apache.logging.log4j log4j - 2.21.0-SNAPSHOT + ${revision} log4j-to-jul jar From 3a29d49476dd57a8ef0cb838fb04918fef9d5cbd Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Fri, 29 Sep 2023 12:26:29 +0200 Subject: [PATCH 48/65] Add BND configuration to bridges --- log4j-to-jul/pom.xml | 1 - .../main/java/org/apache/logging/log4j/tojul/Activator.java | 4 ++++ .../main/java/org/apache/logging/log4j/tojul/JULProvider.java | 3 +++ .../java/org/apache/logging/log4j/tojul/package-info.java | 3 +++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index cd1bdc5..5edd880 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -31,7 +31,6 @@ ${basedir}/.. Log4j to JUL Documentation /log4j-to-jul - org.apache.logging.tojul diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java index 5dee7ad..11c7c14 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java @@ -17,7 +17,11 @@ package org.apache.logging.log4j.tojul; import org.apache.logging.log4j.util.ProviderActivator; +import org.osgi.annotation.bundle.Header; +import org.osgi.framework.Constants; +@Header(name = Constants.BUNDLE_ACTIVATOR, value = "${@class}") +@Header(name = Constants.BUNDLE_ACTIVATIONPOLICY, value = Constants.ACTIVATION_LAZY) public class Activator extends ProviderActivator { public Activator() { diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java index 27c2eca..9022d9a 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java @@ -16,6 +16,8 @@ */ package org.apache.logging.log4j.tojul; +import aQute.bnd.annotation.Resolution; +import aQute.bnd.annotation.spi.ServiceProvider; import org.apache.logging.log4j.spi.Provider; /** @@ -23,6 +25,7 @@ * * @author Michael Vorburger.ch for Google */ +@ServiceProvider(value = Provider.class, resolution = Resolution.OPTIONAL) public class JULProvider extends Provider { public JULProvider() { super(20, "2.6.0", JULLoggerContextFactory.class, null); diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java index b6cd969..9cf4602 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java @@ -20,4 +20,7 @@ * * @author Michael Vorburger.ch for Google */ +@Export package org.apache.logging.log4j.tojul; + +import org.osgi.annotation.bundle.Export; From 1d25eb10e5fc5bdf75e90c66a304284e989e9df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20Yaz=C4=B1c=C4=B1?= Date: Thu, 5 Oct 2023 09:51:52 +0200 Subject: [PATCH 49/65] Migrate changelog, site, and docs to the new infra --- log4j-to-jul/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 5edd880..1a7379f 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -28,7 +28,6 @@ The Apache Log4j binding between Log4j 2 API and java.util.logging (JUL). 2022 - ${basedir}/.. Log4j to JUL Documentation /log4j-to-jul From 0cf4a7000f68dccbcb822c27d352b885f19ed710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20Yaz=C4=B1c=C4=B1?= Date: Thu, 5 Oct 2023 12:45:34 +0200 Subject: [PATCH 50/65] Swap `/pom.xml` and `/log4j-bom/pom.xml` - `/pom.xml` is moved to `/log4j-parent/pom.xml` - `/log4j-bom/pom.xml` is moved to `/pom.xml` - Implements the BOM organization described by Maven[1]. That is, `parent` inherits from `bom`. - Takes advantage of `flatten-bom` provided by `logging-parent` - Identical scheme to the one found in `-tools` and `-transformation` [1] https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms --- log4j-to-jul/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 1a7379f..f7bea6b 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -21,6 +21,7 @@ org.apache.logging.log4j log4j ${revision} + ../log4j-parent log4j-to-jul jar From d63f005f89d4f340aba85ef6e7bd56ec10c6ef8a Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Fri, 6 Oct 2023 11:58:53 +0200 Subject: [PATCH 51/65] Remove `log4j-core` from some processor paths There are many modules that do not depend on `log4j-core` and they can be easily built without it on the processor path. --- log4j-to-jul/pom.xml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index f7bea6b..0df4b41 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -64,4 +64,23 @@ + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + + com.google.errorprone + error_prone_core + ${error-prone.version} + + + + + + + From f9e89a448dc37a63f7d110a1c56ba40068608f30 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Fri, 6 Oct 2023 12:52:17 +0200 Subject: [PATCH 52/65] Add `log4j-core` to some modules processor path Since the split between modules that have Log4j Core plugins and those that don't is about 50/50, it is more proper to add `log4j-core` to some modules instead of removing it from others (and copy/paste all other options). --- log4j-to-jul/pom.xml | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 0df4b41..f839bf2 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -63,24 +63,4 @@ test - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - - com.google.errorprone - error_prone_core - ${error-prone.version} - - - - - - - From ded9f184b17c309d00d6a153147bbb0add8dc696 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Sun, 8 Oct 2023 07:31:46 +0200 Subject: [PATCH 53/65] Add OSGi package versioning and fix API breaking changes In order to prevent API breaking changes, this: * adds [`bnd-baseline-maven-plugin`](https://github.com/bndtools/bnd/tree/master/maven-plugins/bnd-baseline-maven-plugin), * fix the API changes that would require a major version bump, * set the OSGi version of each packages to `2.20.1` or `2.21.0`, depending on the kind of changes the package underwent since the `2.20.0` release. --- .../main/java/org/apache/logging/log4j/tojul/package-info.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java index 9cf4602..f333fff 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java @@ -21,6 +21,8 @@ * @author Michael Vorburger.ch for Google */ @Export +@Version("2.20.1") package org.apache.logging.log4j.tojul; import org.osgi.annotation.bundle.Export; +import org.osgi.annotation.versioning.Version; From 85cf5c24c228b44e9973b8eb0676c7067ee355a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20Yaz=C4=B1c=C4=B1?= Date: Wed, 1 Nov 2023 14:09:12 +0100 Subject: [PATCH 54/65] Remove unused Maven properties --- log4j-to-jul/pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index f839bf2..0c4babf 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -28,10 +28,6 @@ Apache Log4j to JUL Bridge The Apache Log4j binding between Log4j 2 API and java.util.logging (JUL). 2022 - - Log4j to JUL Documentation - /log4j-to-jul - org.osgi From d59fd61cda97b10cce9d29eac2fe9d277e341f98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20Yaz=C4=B1c=C4=B1?= Date: Thu, 16 Nov 2023 11:22:14 +0100 Subject: [PATCH 55/65] Apply Palantir formatter --- .../apache/logging/log4j/tojul/JULLogger.java | 147 +++++++++++++----- .../logging/log4j/tojul/JULLoggerContext.java | 5 +- .../log4j/tojul/JULLoggerContextFactory.java | 17 +- .../log4j/tojul/LazyLog4jLogRecord.java | 1 - .../logging/log4j/tojul/JULLoggerTest.java | 7 +- .../logging/log4j/tojul/LoggerTest.java | 77 +++++---- 6 files changed, 171 insertions(+), 83 deletions(-) diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java index cbd8f53..1108107 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java @@ -16,16 +16,15 @@ */ package org.apache.logging.log4j.tojul; -import java.util.logging.Logger; +import static java.util.Objects.requireNonNull; +import java.util.logging.Logger; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.message.MessageFactory; import org.apache.logging.log4j.spi.AbstractLogger; -import static java.util.Objects.requireNonNull; - /** * Implementation of {@link org.apache.logging.log4j.Logger} that's backed by a {@link Logger}. * @@ -55,12 +54,14 @@ public Logger getWrappedLogger() { } @Override - public void logMessage(final String fqcn, final Level level, final Marker marker, final Message message, final Throwable t) { + public void logMessage( + final String fqcn, final Level level, final Marker marker, final Message message, final Throwable t) { final java.util.logging.Level julLevel = convertLevel(level); if (!logger.isLoggable(julLevel)) { return; } - final LazyLog4jLogRecord record = new LazyLog4jLogRecord(fqcn, julLevel, message.getFormattedMessage()); // NOT getFormat() + final LazyLog4jLogRecord record = + new LazyLog4jLogRecord(fqcn, julLevel, message.getFormattedMessage()); // NOT getFormat() // NOT record.setParameters(message.getParameters()); BECAUSE getFormattedMessage() NOT getFormat() record.setLoggerName(getName()); record.setThrown(t == null ? message.getThrowable() : t); @@ -68,12 +69,14 @@ public void logMessage(final String fqcn, final Level level, final Marker marker } // Convert Level in Log4j scale to JUL scale. - // See getLevel() for the mapping. Note that JUL's FINEST & CONFIG are never returned because Log4j has no such levels, and - // that Log4j's FATAL is simply mapped to JUL's SEVERE as is Log4j's ERROR because JUL does not distinguish between ERROR and FATAL. + // See getLevel() for the mapping. Note that JUL's FINEST & CONFIG are never returned because Log4j has no such + // levels, and + // that Log4j's FATAL is simply mapped to JUL's SEVERE as is Log4j's ERROR because JUL does not distinguish between + // ERROR and FATAL. private java.util.logging.Level convertLevel(final Level level) { switch (level.getStandardLevel()) { - // Test in logical order of likely frequency of use - // Must be kept in sync with #getLevel() + // Test in logical order of likely frequency of use + // Must be kept in sync with #getLevel() case ALL: return java.util.logging.Level.ALL; case TRACE: @@ -91,10 +94,14 @@ private java.util.logging.Level convertLevel(final Level level) { case OFF: return java.util.logging.Level.OFF; default: - // This is tempting: throw new IllegalStateException("Impossible Log4j Level encountered: " + level.intLevel()); - // But it's not a great idea, security wise. If an attacker *SOMEHOW* managed to create a Log4j Level instance - // with an unexpected level (through JVM de-serialization, despite readResolve() { return Level.valueOf(this.name); }, - // or whatever other means), then we would blow up in a very unexpected place and way. Let us therefore instead just + // This is tempting: throw new IllegalStateException("Impossible Log4j Level encountered: " + + // level.intLevel()); + // But it's not a great idea, security wise. If an attacker *SOMEHOW* managed to create a Log4j Level + // instance + // with an unexpected level (through JVM de-serialization, despite readResolve() { return + // Level.valueOf(this.name); }, + // or whatever other means), then we would blow up in a very unexpected place and way. Let us therefore + // instead just // return SEVERE for unexpected values, because that's more likely to be noticed than a FINER. // Greetings, Michael Vorburger.ch , for Google, on 2021.12.24. return java.util.logging.Level.SEVERE; @@ -130,7 +137,7 @@ public Level getLevel() { if (julLevel <= java.util.logging.Level.FINER.intValue()) { return Level.TRACE; } - if (julLevel <= java.util.logging.Level.FINE.intValue()) { // includes FINER + if (julLevel <= java.util.logging.Level.FINE.intValue()) { // includes FINER return Level.DEBUG; } if (julLevel <= java.util.logging.Level.INFO.intValue()) { // includes CONFIG @@ -153,7 +160,8 @@ private java.util.logging.Level getEffectiveJULLevel() { if (current.getLevel() != null) { return current.getLevel(); } - // This is a safety fallback that is typically never reached, because usually the root Logger.getLogger("") has a Level. + // This is a safety fallback that is typically never reached, because usually the root Logger.getLogger("") has + // a Level. // Since JDK 8 the LogManager$RootLogger does not have a default level, just a default effective level of INFO. return java.util.logging.Level.INFO; } @@ -195,65 +203,124 @@ public boolean isEnabled(final Level level, final Marker marker, final String me } @Override - public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, - final Object p1) { + public boolean isEnabled( + final Level level, final Marker marker, final String message, final Object p0, final Object p1) { return isEnabledFor(level, marker); } @Override - public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, - final Object p1, final Object p2) { + public boolean isEnabled( + final Level level, + final Marker marker, + final String message, + final Object p0, + final Object p1, + final Object p2) { return isEnabledFor(level, marker); } @Override - public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, - final Object p1, final Object p2, final Object p3) { + public boolean isEnabled( + final Level level, + final Marker marker, + final String message, + final Object p0, + final Object p1, + final Object p2, + final Object p3) { return isEnabledFor(level, marker); } @Override - public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, - final Object p1, final Object p2, final Object p3, + public boolean isEnabled( + final Level level, + final Marker marker, + final String message, + final Object p0, + final Object p1, + final Object p2, + final Object p3, final Object p4) { return isEnabledFor(level, marker); } @Override - public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, - final Object p1, final Object p2, final Object p3, - final Object p4, final Object p5) { + public boolean isEnabled( + final Level level, + final Marker marker, + final String message, + final Object p0, + final Object p1, + final Object p2, + final Object p3, + final Object p4, + final Object p5) { return isEnabledFor(level, marker); } @Override - public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, - final Object p1, final Object p2, final Object p3, - final Object p4, final Object p5, final Object p6) { + public boolean isEnabled( + final Level level, + final Marker marker, + final String message, + final Object p0, + final Object p1, + final Object p2, + final Object p3, + final Object p4, + final Object p5, + final Object p6) { return isEnabledFor(level, marker); } @Override - public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, - final Object p1, final Object p2, final Object p3, - final Object p4, final Object p5, final Object p6, + public boolean isEnabled( + final Level level, + final Marker marker, + final String message, + final Object p0, + final Object p1, + final Object p2, + final Object p3, + final Object p4, + final Object p5, + final Object p6, final Object p7) { return isEnabledFor(level, marker); } @Override - public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, - final Object p1, final Object p2, final Object p3, - final Object p4, final Object p5, final Object p6, - final Object p7, final Object p8) { + public boolean isEnabled( + final Level level, + final Marker marker, + final String message, + final Object p0, + final Object p1, + final Object p2, + final Object p3, + final Object p4, + final Object p5, + final Object p6, + final Object p7, + final Object p8) { return isEnabledFor(level, marker); } @Override - public boolean isEnabled(final Level level, final Marker marker, final String message, final Object p0, - final Object p1, final Object p2, final Object p3, - final Object p4, final Object p5, final Object p6, - final Object p7, final Object p8, final Object p9) { + public boolean isEnabled( + final Level level, + final Marker marker, + final String message, + final Object p0, + final Object p1, + final Object p2, + final Object p3, + final Object p4, + final Object p5, + final Object p6, + final Object p7, + final Object p8, + final Object p9) { return isEnabledFor(level, marker); } diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java index fe8f3ef..7d2c235 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java @@ -17,7 +17,6 @@ package org.apache.logging.log4j.tojul; import java.util.logging.Logger; - import org.apache.logging.log4j.message.MessageFactory; import org.apache.logging.log4j.spi.ExtendedLogger; import org.apache.logging.log4j.spi.LoggerContext; @@ -50,8 +49,8 @@ public ExtendedLogger getLogger(final String name) { @Override public ExtendedLogger getLogger(final String name, final MessageFactory messageFactory) { if (!loggerRegistry.hasLogger(name, messageFactory)) { - loggerRegistry.putIfAbsent(name, messageFactory, - new JULLogger(name, messageFactory, Logger.getLogger(name))); + loggerRegistry.putIfAbsent( + name, messageFactory, new JULLogger(name, messageFactory, Logger.getLogger(name))); } return loggerRegistry.getLogger(name, messageFactory); } diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContextFactory.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContextFactory.java index 2a848f5..f241e07 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContextFactory.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContextFactory.java @@ -17,7 +17,6 @@ package org.apache.logging.log4j.tojul; import java.net.URI; - import org.apache.logging.log4j.spi.LoggerContext; import org.apache.logging.log4j.spi.LoggerContextFactory; import org.apache.logging.log4j.status.StatusLogger; @@ -50,20 +49,24 @@ public JULLoggerContextFactory() { } @Override - public LoggerContext getContext(final String fqcn, final ClassLoader loader, final Object externalContext, - final boolean currentContext) { + public LoggerContext getContext( + final String fqcn, final ClassLoader loader, final Object externalContext, final boolean currentContext) { return context; } @Override - public LoggerContext getContext(final String fqcn, final ClassLoader loader, final Object externalContext, - final boolean currentContext, final URI configLocation, final String name) { + public LoggerContext getContext( + final String fqcn, + final ClassLoader loader, + final Object externalContext, + final boolean currentContext, + final URI configLocation, + final String name) { return context; } @Override - public void removeContext(final LoggerContext ignored) { - } + public void removeContext(final LoggerContext ignored) {} @Override public boolean isClassLoaderDependent() { diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java index b4d8fb5..014aa8c 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java @@ -18,7 +18,6 @@ import java.util.logging.Level; import java.util.logging.LogRecord; - import org.apache.logging.log4j.util.StackLocatorUtil; /** diff --git a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java index 3b3aa28..9f70a01 100644 --- a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java +++ b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java @@ -16,19 +16,18 @@ */ package org.apache.logging.log4j.tojul; +import static org.junit.jupiter.api.Assertions.assertEquals; + import org.apache.logging.log4j.Level; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; - public class JULLoggerTest { @Test public void testNotNullEffectiveLevel() { // Emulates the root logger found in Tomcat, with a null level // See: https://bz.apache.org/bugzilla/show_bug.cgi?id=66184 - final java.util.logging.Logger julLogger = new java.util.logging.Logger("", null) { - }; + final java.util.logging.Logger julLogger = new java.util.logging.Logger("", null) {}; final JULLogger logger = new JULLogger("", julLogger); assertEquals(Level.INFO, logger.getLevel()); } diff --git a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java index a028826..f27f17d 100644 --- a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java +++ b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java @@ -16,19 +16,18 @@ */ package org.apache.logging.log4j.tojul; +import static org.assertj.core.api.Assertions.assertThat; + +import com.google.common.testing.TestLogHandler; import java.io.IOException; import java.util.List; import java.util.logging.Level; import java.util.logging.LogRecord; - -import com.google.common.testing.TestLogHandler; import org.apache.logging.log4j.LogManager; import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.assertj.core.api.Assertions.assertThat; - public class LoggerTest { // Save levels so that we can reset them @After clearLogs() @@ -44,24 +43,26 @@ public class LoggerTest { // https://javadoc.io/doc/com.google.guava/guava-testlib/latest/com/google/common/testing/TestLogHandler.html private TestLogHandler handler; - - @Before public void setupLogCapture() { + @Before + public void setupLogCapture() { handler = new TestLogHandler(); // Beware, the order here should not be changed! // Let the bridge do whatever it does BEFORE we create a JUL Logger (which SHOULD be the same) log4jLogger = LogManager.getLogger(getClass()); assertThat(log4jLogger).isInstanceOf(JULLogger.class); julLogger = java.util.logging.Logger.getLogger(getClass().getName()); - assertThat(julLogger).isSameAs(((JULLogger)log4jLogger).getWrappedLogger()); + assertThat(julLogger).isSameAs(((JULLogger) log4jLogger).getWrappedLogger()); julLogger.addHandler(handler); julLoggerDefaultLevel = julLogger.getLevel(); - // Check that there is no configuration file which invalidates our assumption that the root logger is the parent of our julLogger + // Check that there is no configuration file which invalidates our assumption that the root logger is the parent + // of our julLogger assertThat(julLogger.getParent()).isEqualTo(rootLogger); } - @After public void clearLogs() { + @After + public void clearLogs() { julLogger.removeHandler(handler); // Reset all Levels what any tests set anymore julLogger.setLevel(julLoggerDefaultLevel); @@ -69,7 +70,8 @@ public class LoggerTest { globalLogger.setLevel(globalLevel); } - @Test public void infoAtInfo() { + @Test + public void infoAtInfo() { julLogger.setLevel(Level.INFO); log4jLogger.info("hello, world"); @@ -85,7 +87,8 @@ public class LoggerTest { assertThat(log1.getSourceMethodName()).isEqualTo("infoAtInfo"); } - @Test public void infoAtInfoWithParameters() { + @Test + public void infoAtInfoWithParameters() { julLogger.setLevel(Level.INFO); log4jLogger.info("hello, {}", "world"); @@ -97,7 +100,8 @@ public class LoggerTest { assertThat(log1.getThrown()).isNull(); } - @Test public void errorAtSevereWithException() { + @Test + public void errorAtSevereWithException() { julLogger.setLevel(Level.SEVERE); log4jLogger.error("hello, {}", "world", new IOException("Testing, testing")); @@ -109,67 +113,78 @@ public class LoggerTest { assertThat(log1.getThrown()).isInstanceOf(IOException.class); } - @Test public void infoAtInfoWithLogBuilder() { + @Test + public void infoAtInfoWithLogBuilder() { julLogger.setLevel(Level.INFO); log4jLogger.atInfo().log("hello, world"); assertThat(handler.getStoredLogRecords()).hasSize(1); } - @Test public void infoAtInfoOnParent() { + @Test + public void infoAtInfoOnParent() { julLogger.getParent().setLevel(Level.INFO); log4jLogger.info("hello, world"); assertThat(handler.getStoredLogRecords()).hasSize(1); } - @Test public void infoWithoutAnyLevel() { + @Test + public void infoWithoutAnyLevel() { // We're not setting any level. log4jLogger.info("hello, world"); assertThat(handler.getStoredLogRecords()).hasSize(1); } - @Test public void debugAtInfo() { + @Test + public void debugAtInfo() { julLogger.setLevel(Level.INFO); log4jLogger.debug("hello, world"); assertThat(handler.getStoredLogRecords()).isEmpty(); } - @Test public void debugAtFiner() { + @Test + public void debugAtFiner() { julLogger.setLevel(Level.FINER); log4jLogger.debug("hello, world"); assertThat(handler.getStoredLogRecords()).hasSize(1); } - @Test public void traceAtFine() { + @Test + public void traceAtFine() { julLogger.setLevel(Level.FINE); log4jLogger.trace("hello, world"); assertThat(handler.getStoredLogRecords()).isEmpty(); } - @Test public void traceAtAllOnParent() { + @Test + public void traceAtAllOnParent() { julLogger.getParent().setLevel(Level.ALL); log4jLogger.trace("hello, world"); assertThat(handler.getStoredLogRecords()).hasSize(1); } - @Test public void fatalAtOff() { + @Test + public void fatalAtOff() { julLogger.getParent().setLevel(Level.OFF); log4jLogger.fatal("hello, world"); assertThat(handler.getStoredLogRecords()).isEmpty(); } - @Test public void fatalAtSevere() { + @Test + public void fatalAtSevere() { julLogger.getParent().setLevel(Level.SEVERE); log4jLogger.atFatal().log("hello, world"); assertThat(handler.getStoredLogRecords()).hasSize(1); } - @Test public void warnAtFatal() { + @Test + public void warnAtFatal() { julLogger.getParent().setLevel(Level.SEVERE); log4jLogger.atWarn().log("hello, world"); assertThat(handler.getStoredLogRecords()).isEmpty(); } - @Test public void customLevelJustUnderWarning() { + @Test + public void customLevelJustUnderWarning() { julLogger.getParent().setLevel(new CustomLevel("Just under Warning", Level.WARNING.intValue() - 1)); log4jLogger.info("hello, world"); @@ -182,7 +197,8 @@ public class LoggerTest { assertThat(handler.getStoredLogRecords()).hasSize(2); } - @Test public void customLevelJustAboveWarning() { + @Test + public void customLevelJustAboveWarning() { julLogger.getParent().setLevel(new CustomLevel("Just above Warning", Level.WARNING.intValue() + 1)); log4jLogger.info("hello, world"); @@ -206,7 +222,8 @@ private static class CustomLevel extends Level { * Test that the {@link LogRecord#getSourceClassName()}, which we already tested above in infoAtInfo() * also works as expected if the logging happened in a class that we have called (indirect), not in the test method itself. */ - @Test public void indirectSource() { + @Test + public void indirectSource() { java.util.logging.Logger.getLogger(Another.class.getName()).setLevel(Level.INFO); new Another(handler); final List logs = handler.getStoredLogRecords(); @@ -218,14 +235,17 @@ private static class CustomLevel extends Level { static class Another { org.apache.logging.log4j.Logger anotherLog4jLogger = LogManager.getLogger(getClass()); - java.util.logging.Logger anotherJULLogger = java.util.logging.Logger.getLogger(getClass().getName()); + java.util.logging.Logger anotherJULLogger = + java.util.logging.Logger.getLogger(getClass().getName()); + Another(final TestLogHandler handler) { anotherJULLogger.addHandler(handler); anotherLog4jLogger.info("hello, another world"); } } - @Test public void placeholdersInFormat() { + @Test + public void placeholdersInFormat() { julLogger.setLevel(Level.INFO); log4jLogger.info("hello, {0} {}", "world"); @@ -236,7 +256,8 @@ static class Another { assertThat(formattedMessage).isEqualTo("hello, {0} world"); } - @Test public void placeholdersInFormattedMessage() { + @Test + public void placeholdersInFormattedMessage() { julLogger.setLevel(Level.INFO); log4jLogger.info("hello, {}", "{0} world"); From 64230e559be5553f684f592acc5204fa45eb4b1f Mon Sep 17 00:00:00 2001 From: Matt Sicker Date: Sun, 16 Jan 2022 19:44:36 -0600 Subject: [PATCH 56/65] Update to-jul test to JUnit 5 Signed-off-by: Matt Sicker --- .../org/apache/logging/log4j/tojul/LoggerTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java index f27f17d..c2d6519 100644 --- a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java +++ b/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java @@ -24,9 +24,9 @@ import java.util.logging.Level; import java.util.logging.LogRecord; import org.apache.logging.log4j.LogManager; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class LoggerTest { @@ -43,7 +43,7 @@ public class LoggerTest { // https://javadoc.io/doc/com.google.guava/guava-testlib/latest/com/google/common/testing/TestLogHandler.html private TestLogHandler handler; - @Before + @BeforeEach public void setupLogCapture() { handler = new TestLogHandler(); // Beware, the order here should not be changed! @@ -61,7 +61,7 @@ public void setupLogCapture() { assertThat(julLogger.getParent()).isEqualTo(rootLogger); } - @After + @AfterEach public void clearLogs() { julLogger.removeHandler(handler); // Reset all Levels what any tests set anymore From 2cd0208ffae5f2cda8952d2b5beb10f63d833302 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Tue, 19 Mar 2024 14:11:41 +0100 Subject: [PATCH 57/65] Remove reflection from `log4j-to-jul` and `log4j-to-slf4j` By removing the reflective instantiation of `LoggerContextFactory` and `ThreadContextMap`, we make `log4j-to-jul` and `log4j-to-slf4j` more GraalVM-friendly. --- .../apache/logging/log4j/tojul/JULProvider.java | 16 +++++++++++++++- .../apache/logging/log4j/tojul/package-info.java | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java index 9022d9a..0f371f4 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java @@ -18,6 +18,7 @@ import aQute.bnd.annotation.Resolution; import aQute.bnd.annotation.spi.ServiceProvider; +import org.apache.logging.log4j.spi.LoggerContextFactory; import org.apache.logging.log4j.spi.Provider; /** @@ -27,7 +28,20 @@ */ @ServiceProvider(value = Provider.class, resolution = Resolution.OPTIONAL) public class JULProvider extends Provider { + private static final LoggerContextFactory CONTEXT_FACTORY = new JULLoggerContextFactory(); + public JULProvider() { - super(20, "2.6.0", JULLoggerContextFactory.class, null); + super(20, CURRENT_VERSION); + } + + @Override + public LoggerContextFactory getLoggerContextFactory() { + return CONTEXT_FACTORY; + } + + @Override + public String getThreadContextMap() { + // JUL does not provide an MDC implementation + return NO_OP_CONTEXT_MAP; } } diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java index f333fff..aa117c7 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java @@ -21,7 +21,7 @@ * @author Michael Vorburger.ch for Google */ @Export -@Version("2.20.1") +@Version("2.24.0") package org.apache.logging.log4j.tojul; import org.osgi.annotation.bundle.Export; From 3697a1cb0c91a7119267dfa7ea18df16578065a1 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Fri, 21 Jun 2024 16:53:26 +0200 Subject: [PATCH 58/65] Clean up `ThreadContextMap` implementations - Make `StringArray` the default thread context map - Remove `CopyOnWriteSortedArrayThreadContextMap` - Move `GarbageFreeSortedArrayThreadContextMap` to `log4j-core` --- log4j-to-jul/pom.xml | 13 +++++++++++++ .../org/apache/logging/log4j/tojul/JULProvider.java | 10 +++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 0c4babf..25caed1 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -28,7 +28,20 @@ Apache Log4j to JUL Bridge The Apache Log4j binding between Log4j 2 API and java.util.logging (JUL). 2022 + + + + + org.jspecify.*;resolution:=optional + + + + + org.jspecify + jspecify + provided + org.osgi org.osgi.core diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java index 0f371f4..7497e48 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java @@ -19,19 +19,23 @@ import aQute.bnd.annotation.Resolution; import aQute.bnd.annotation.spi.ServiceProvider; import org.apache.logging.log4j.spi.LoggerContextFactory; +import org.apache.logging.log4j.spi.NoOpThreadContextMap; import org.apache.logging.log4j.spi.Provider; +import org.apache.logging.log4j.spi.ThreadContextMap; +import org.jspecify.annotations.NullMarked; /** * Bind the Log4j API to JUL. * * @author Michael Vorburger.ch for Google */ +@NullMarked @ServiceProvider(value = Provider.class, resolution = Resolution.OPTIONAL) public class JULProvider extends Provider { private static final LoggerContextFactory CONTEXT_FACTORY = new JULLoggerContextFactory(); public JULProvider() { - super(20, CURRENT_VERSION); + super(20, CURRENT_VERSION, JULLoggerContextFactory.class, NoOpThreadContextMap.class); } @Override @@ -40,8 +44,8 @@ public LoggerContextFactory getLoggerContextFactory() { } @Override - public String getThreadContextMap() { + public ThreadContextMap getThreadContextMapInstance() { // JUL does not provide an MDC implementation - return NO_OP_CONTEXT_MAP; + return NoOpThreadContextMap.INSTANCE; } } From 85f30a402e3ddc9f4dc8ec8a2179a5dc1bd9c7b0 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Sun, 8 Sep 2024 10:58:36 +0200 Subject: [PATCH 59/65] Fail build for `static transitive` modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds a Groovy script that fails the build if any optional JPMS module has the `transitive` qualifier. We remove the `transitive` modifier from all optional dependencies. Closes #2929. Co-authored-by: Volkan Yazıcı --- log4j-to-jul/pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/log4j-to-jul/pom.xml b/log4j-to-jul/pom.xml index 25caed1..54899fa 100644 --- a/log4j-to-jul/pom.xml +++ b/log4j-to-jul/pom.xml @@ -34,6 +34,10 @@ org.jspecify.*;resolution:=optional + + + org.jspecify;transitive=false + From b77e31e5ebd077a41997719222d6c9789e10e700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20Yaz=C4=B1c=C4=B1?= Date: Mon, 16 Sep 2024 13:15:33 +0200 Subject: [PATCH 60/65] Implement `MessageFactory`-namespaced logger registry (#2936) Co-authored-by: Piotr P. Karwasz --- .../logging/log4j/tojul/JULLoggerContext.java | 33 +++++++++++-------- .../logging/log4j/tojul/package-info.java | 2 +- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java index 7d2c235..3cca831 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java @@ -18,9 +18,11 @@ import java.util.logging.Logger; import org.apache.logging.log4j.message.MessageFactory; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.apache.logging.log4j.spi.ExtendedLogger; import org.apache.logging.log4j.spi.LoggerContext; import org.apache.logging.log4j.spi.LoggerRegistry; +import org.jspecify.annotations.Nullable; /** * Implementation of Log4j {@link LoggerContext} SPI. @@ -29,8 +31,11 @@ * @author Michael Vorburger.ch for Google */ class JULLoggerContext implements LoggerContext { + private final LoggerRegistry loggerRegistry = new LoggerRegistry<>(); + private static final MessageFactory DEFAULT_MESSAGE_FACTORY = ParameterizedMessageFactory.INSTANCE; + // This implementation is strongly inspired by org.apache.logging.slf4j.SLF4JLoggerContext @Override @@ -40,29 +45,31 @@ public Object getExternalContext() { @Override public ExtendedLogger getLogger(final String name) { - if (!loggerRegistry.hasLogger(name)) { - loggerRegistry.putIfAbsent(name, null, new JULLogger(name, Logger.getLogger(name))); - } - return loggerRegistry.getLogger(name); + return getLogger(name, null); } @Override - public ExtendedLogger getLogger(final String name, final MessageFactory messageFactory) { - if (!loggerRegistry.hasLogger(name, messageFactory)) { - loggerRegistry.putIfAbsent( - name, messageFactory, new JULLogger(name, messageFactory, Logger.getLogger(name))); - } - return loggerRegistry.getLogger(name, messageFactory); + public ExtendedLogger getLogger(final String name, @Nullable final MessageFactory messageFactory) { + final MessageFactory effectiveMessageFactory = + messageFactory != null ? messageFactory : DEFAULT_MESSAGE_FACTORY; + return loggerRegistry.computeIfAbsent(name, effectiveMessageFactory, JULLoggerContext::createLogger); + } + + private static ExtendedLogger createLogger(final String name, @Nullable final MessageFactory messageFactory) { + final Logger logger = Logger.getLogger(name); + return new JULLogger(name, messageFactory, logger); } @Override public boolean hasLogger(final String name) { - return loggerRegistry.hasLogger(name); + return loggerRegistry.hasLogger(name, DEFAULT_MESSAGE_FACTORY); } @Override - public boolean hasLogger(final String name, final MessageFactory messageFactory) { - return loggerRegistry.hasLogger(name, messageFactory); + public boolean hasLogger(final String name, @Nullable final MessageFactory messageFactory) { + final MessageFactory effectiveMessageFactory = + messageFactory != null ? messageFactory : DEFAULT_MESSAGE_FACTORY; + return loggerRegistry.hasLogger(name, effectiveMessageFactory); } @Override diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java index aa117c7..68812bb 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java @@ -21,7 +21,7 @@ * @author Michael Vorburger.ch for Google */ @Export -@Version("2.24.0") +@Version("2.25.0") package org.apache.logging.log4j.tojul; import org.osgi.annotation.bundle.Export; From ac262691185b302cf3e2de020d18fc82a1ce49e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20Yaz=C4=B1c=C4=B1?= Date: Tue, 17 Sep 2024 20:39:29 +0200 Subject: [PATCH 61/65] Improvements on the logger message factory namespacing (#2936) --- .../java/org/apache/logging/log4j/tojul/JULLoggerContext.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java index 3cca831..9f92dca 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java @@ -45,7 +45,7 @@ public Object getExternalContext() { @Override public ExtendedLogger getLogger(final String name) { - return getLogger(name, null); + return getLogger(name, DEFAULT_MESSAGE_FACTORY); } @Override From 3cb0b39aae7cd08995ff234ae9fe93bd853a91e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20Yaz=C4=B1c=C4=B1?= Date: Tue, 17 Sep 2024 20:39:29 +0200 Subject: [PATCH 62/65] Implement `MessageFactory`-namespaced logger registry (#2961) --- .../logging/log4j/tojul/JULLoggerContext.java | 17 +++++++++++------ .../logging/log4j/tojul/package-info.java | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java index 9f92dca..b041d4d 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java @@ -22,7 +22,6 @@ import org.apache.logging.log4j.spi.ExtendedLogger; import org.apache.logging.log4j.spi.LoggerContext; import org.apache.logging.log4j.spi.LoggerRegistry; -import org.jspecify.annotations.Nullable; /** * Implementation of Log4j {@link LoggerContext} SPI. @@ -45,17 +44,23 @@ public Object getExternalContext() { @Override public ExtendedLogger getLogger(final String name) { - return getLogger(name, DEFAULT_MESSAGE_FACTORY); + return getLogger(name, null); } @Override - public ExtendedLogger getLogger(final String name, @Nullable final MessageFactory messageFactory) { + public ExtendedLogger getLogger(final String name, final MessageFactory messageFactory) { final MessageFactory effectiveMessageFactory = messageFactory != null ? messageFactory : DEFAULT_MESSAGE_FACTORY; - return loggerRegistry.computeIfAbsent(name, effectiveMessageFactory, JULLoggerContext::createLogger); + final ExtendedLogger oldLogger = loggerRegistry.getLogger(name, effectiveMessageFactory); + if (oldLogger != null) { + return oldLogger; + } + final ExtendedLogger newLogger = createLogger(name, effectiveMessageFactory); + loggerRegistry.putIfAbsent(name, effectiveMessageFactory, newLogger); + return loggerRegistry.getLogger(name, effectiveMessageFactory); } - private static ExtendedLogger createLogger(final String name, @Nullable final MessageFactory messageFactory) { + private static ExtendedLogger createLogger(final String name, final MessageFactory messageFactory) { final Logger logger = Logger.getLogger(name); return new JULLogger(name, messageFactory, logger); } @@ -66,7 +71,7 @@ public boolean hasLogger(final String name) { } @Override - public boolean hasLogger(final String name, @Nullable final MessageFactory messageFactory) { + public boolean hasLogger(final String name, final MessageFactory messageFactory) { final MessageFactory effectiveMessageFactory = messageFactory != null ? messageFactory : DEFAULT_MESSAGE_FACTORY; return loggerRegistry.hasLogger(name, effectiveMessageFactory); diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java index 68812bb..8308d5c 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java @@ -21,7 +21,7 @@ * @author Michael Vorburger.ch for Google */ @Export -@Version("2.25.0") +@Version("2.24.1") package org.apache.logging.log4j.tojul; import org.osgi.annotation.bundle.Export; From 524c222bb46dc5d8831c3e3e6c3dce5ddef73265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20Yaz=C4=B1c=C4=B1?= Date: Tue, 17 Sep 2024 21:11:00 +0200 Subject: [PATCH 63/65] Improvements on the logger message factory namespacing (#2961) --- .../java/org/apache/logging/log4j/tojul/JULLoggerContext.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java index b041d4d..ae6697f 100644 --- a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java +++ b/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java @@ -44,7 +44,7 @@ public Object getExternalContext() { @Override public ExtendedLogger getLogger(final String name) { - return getLogger(name, null); + return getLogger(name, DEFAULT_MESSAGE_FACTORY); } @Override From cc8eedb63c4984651ad3ab32c44001a200942b19 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Wed, 6 Nov 2024 13:03:50 +0100 Subject: [PATCH 64/65] Rename `log4j-to-jul` to `log4j-api-to-jul` --- {log4j-to-jul => log4j-api-to-jul}/pom.xml | 0 .../src/main/java/org/apache/logging/log4j/tojul/Activator.java | 0 .../src/main/java/org/apache/logging/log4j/tojul/JULLogger.java | 0 .../java/org/apache/logging/log4j/tojul/JULLoggerContext.java | 0 .../org/apache/logging/log4j/tojul/JULLoggerContextFactory.java | 0 .../src/main/java/org/apache/logging/log4j/tojul/JULProvider.java | 0 .../java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java | 0 .../main/java/org/apache/logging/log4j/tojul/package-info.java | 0 .../META-INF/services/org.apache.logging.log4j.spi.Provider | 0 .../test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java | 0 .../src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename {log4j-to-jul => log4j-api-to-jul}/pom.xml (100%) rename {log4j-to-jul => log4j-api-to-jul}/src/main/java/org/apache/logging/log4j/tojul/Activator.java (100%) rename {log4j-to-jul => log4j-api-to-jul}/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java (100%) rename {log4j-to-jul => log4j-api-to-jul}/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java (100%) rename {log4j-to-jul => log4j-api-to-jul}/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContextFactory.java (100%) rename {log4j-to-jul => log4j-api-to-jul}/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java (100%) rename {log4j-to-jul => log4j-api-to-jul}/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java (100%) rename {log4j-to-jul => log4j-api-to-jul}/src/main/java/org/apache/logging/log4j/tojul/package-info.java (100%) rename {log4j-to-jul => log4j-api-to-jul}/src/main/resources/META-INF/services/org.apache.logging.log4j.spi.Provider (100%) rename {log4j-to-jul => log4j-api-to-jul}/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java (100%) rename {log4j-to-jul => log4j-api-to-jul}/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java (100%) diff --git a/log4j-to-jul/pom.xml b/log4j-api-to-jul/pom.xml similarity index 100% rename from log4j-to-jul/pom.xml rename to log4j-api-to-jul/pom.xml diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java b/log4j-api-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java similarity index 100% rename from log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java rename to log4j-api-to-jul/src/main/java/org/apache/logging/log4j/tojul/Activator.java diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java b/log4j-api-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java similarity index 100% rename from log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java rename to log4j-api-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLogger.java diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java b/log4j-api-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java similarity index 100% rename from log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java rename to log4j-api-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContext.java diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContextFactory.java b/log4j-api-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContextFactory.java similarity index 100% rename from log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContextFactory.java rename to log4j-api-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULLoggerContextFactory.java diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java b/log4j-api-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java similarity index 100% rename from log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java rename to log4j-api-to-jul/src/main/java/org/apache/logging/log4j/tojul/JULProvider.java diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java b/log4j-api-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java similarity index 100% rename from log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java rename to log4j-api-to-jul/src/main/java/org/apache/logging/log4j/tojul/LazyLog4jLogRecord.java diff --git a/log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java b/log4j-api-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java similarity index 100% rename from log4j-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java rename to log4j-api-to-jul/src/main/java/org/apache/logging/log4j/tojul/package-info.java diff --git a/log4j-to-jul/src/main/resources/META-INF/services/org.apache.logging.log4j.spi.Provider b/log4j-api-to-jul/src/main/resources/META-INF/services/org.apache.logging.log4j.spi.Provider similarity index 100% rename from log4j-to-jul/src/main/resources/META-INF/services/org.apache.logging.log4j.spi.Provider rename to log4j-api-to-jul/src/main/resources/META-INF/services/org.apache.logging.log4j.spi.Provider diff --git a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java b/log4j-api-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java similarity index 100% rename from log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java rename to log4j-api-to-jul/src/test/java/org/apache/logging/log4j/tojul/JULLoggerTest.java diff --git a/log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java b/log4j-api-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java similarity index 100% rename from log4j-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java rename to log4j-api-to-jul/src/test/java/org/apache/logging/log4j/tojul/LoggerTest.java From 9530a3e2e4b0c0a02fbf86dc16e6959b57e960d7 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Wed, 6 Nov 2024 14:05:01 +0100 Subject: [PATCH 65/65] Fix build --- log4j-api-to-jul/pom.xml | 42 +++++++++++--------------- parent/pom.xml | 65 +++++++++++++++++++++++++++++++++++++++- pom.xml | 11 ++++++- spotbugs-exclude.xml | 37 +++++++++++++++++++++++ 4 files changed, 129 insertions(+), 26 deletions(-) create mode 100644 spotbugs-exclude.xml diff --git a/log4j-api-to-jul/pom.xml b/log4j-api-to-jul/pom.xml index 54899fa..ed2b71d 100644 --- a/log4j-api-to-jul/pom.xml +++ b/log4j-api-to-jul/pom.xml @@ -19,61 +19,55 @@ 4.0.0 org.apache.logging.log4j - log4j + log4j-jdk-parent ${revision} - ../log4j-parent + ../parent - log4j-to-jul + + log4j-api-to-jul jar - Apache Log4j to JUL Bridge + Log4j API to JUL logging bridge The Apache Log4j binding between Log4j 2 API and java.util.logging (JUL). + 2022 - - - org.jspecify.*;resolution:=optional - - - - org.jspecify;transitive=false - + + 1.8.0 - - org.jspecify - jspecify - provided - + org.osgi - org.osgi.core + org.osgi.framework + ${osgi.framework.version} provided + org.apache.logging.log4j log4j-api + org.assertj assertj-core test + com.google.guava guava-testlib + 33.3.1-jre test + org.junit.jupiter - junit-jupiter-engine - test - - - org.junit.vintage - junit-vintage-engine + junit-jupiter-api test + diff --git a/parent/pom.xml b/parent/pom.xml index b7a4e2d..65886d1 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -31,22 +31,85 @@ https://logging.apache.org/log4j/2.x/manual/installation.html + + false + 3.26.3 + 7.0.0 + 2.2 + 1.0.0 + 5.11.3 2.24.1 + 2.0.0 + 1.1.2 + + org.hamcrest + hamcrest + ${hamcrest.version} + + + + org.assertj + assertj-bom + ${assertj.version} + pom + import + + org.apache.logging.log4j - log4j-api + log4j-bom ${log4j.version} + pom + import + + + + org.junit + junit-bom + ${junit.version} + pom + import + + + + biz.aQute.bnd + biz.aQute.bnd.annotation + ${bnd.annotation.version} + provided + + + + org.jspecify + jspecify + ${jspecify.version} + + + + org.osgi + org.osgi.annotation.bundle + ${osgi.bundle.version} + provided + + + + org.osgi + org.osgi.annotation.versioning + ${osgi.versioning.version} + + + + diff --git a/pom.xml b/pom.xml index ddca29e..65a200b 100644 --- a/pom.xml +++ b/pom.xml @@ -59,6 +59,7 @@ parent + log4j-api-to-jul @@ -97,7 +98,15 @@ - + + + + org.apache.logging.log4j + log4j-api-to-jul + ${project.version} + + + diff --git a/spotbugs-exclude.xml b/spotbugs-exclude.xml new file mode 100644 index 0000000..b0c83f0 --- /dev/null +++ b/spotbugs-exclude.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + +