This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 10.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.0.x by this push: new e5a5122d2b [Bug 66184] Ensure that all root loggers have a level or parent e5a5122d2b is described below commit e5a5122d2b7dfe5c49e8a74367cb9c17f10e3329 Author: Piotr P. Karwasz <piotr.ra...@karwasz.org> AuthorDate: Thu Jul 28 21:04:22 2022 +0200 [Bug 66184] Ensure that all root loggers have a level or parent Since Java 8 the default level of a root logger is no longer set in the constructor. This PR sets the level to INFO (LogManager's default) if it is absent. --- java/org/apache/juli/ClassLoaderLogManager.java | 4 ++ .../org/apache/juli/TestClassLoaderLogManager.java | 57 ++++++++++++++++++++++ webapps/docs/changelog.xml | 5 ++ 3 files changed, 66 insertions(+) diff --git a/java/org/apache/juli/ClassLoaderLogManager.java b/java/org/apache/juli/ClassLoaderLogManager.java index b290972ec8..7ab5f4a3f4 100644 --- a/java/org/apache/juli/ClassLoaderLogManager.java +++ b/java/org/apache/juli/ClassLoaderLogManager.java @@ -525,6 +525,10 @@ public class ClassLoaderLogManager extends LogManager { if (is != null) { readConfiguration(is, classLoader); } + + if (localRootLogger.getParent() == null && localRootLogger.getLevel() == null) { + localRootLogger.setLevel(Level.INFO); + } try { // Use a ThreadLocal to work around // https://bugs.openjdk.java.net/browse/JDK-8195096 diff --git a/test/org/apache/juli/TestClassLoaderLogManager.java b/test/org/apache/juli/TestClassLoaderLogManager.java index 641a52b936..8628deac16 100644 --- a/test/org/apache/juli/TestClassLoaderLogManager.java +++ b/test/org/apache/juli/TestClassLoaderLogManager.java @@ -16,9 +16,13 @@ */ package org.apache.juli; +import java.io.ByteArrayInputStream; import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.util.Collections; import java.util.Random; +import java.util.logging.Level; import java.util.logging.LogManager; import java.util.logging.Logger; @@ -30,6 +34,8 @@ import org.junit.Test; */ public class TestClassLoaderLogManager { + private static final byte[] EMPTY_BYTES = {}; + @Test public void testReplace() { ClassLoaderLogManager logManager = new ClassLoaderLogManager(); @@ -81,6 +87,26 @@ public class TestClassLoaderLogManager { listThread.setRunning(false); } + /** + * Tests if a per-app root logger has a not {@code null} level. + */ + @Test + public void testBug66184() throws IOException { + final ClassLoader cl = new TestClassLoader(); + final ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(cl); + final ClassLoaderLogManager logManager = new ClassLoaderLogManager(); + logManager.readConfiguration(); + final Logger rootLogger = logManager.getLogger(""); + Assert.assertNotNull("root logger is null", rootLogger); + Assert.assertNull("root logger has a parent", rootLogger.getParent()); + Assert.assertEquals(Level.INFO, rootLogger.getLevel()); + } finally { + Thread.currentThread().setContextClassLoader(oldCL); + } + } + private static class LoggerCreateThread extends Thread { private final LogManager logManager; @@ -133,4 +159,35 @@ public class TestClassLoaderLogManager { this.running = running; } } + + private static class TestClassLoader extends ClassLoader implements WebappProperties { + + @Override + public String getWebappName() { + return "webapp"; + } + + @Override + public String getHostName() { + return "localhost"; + } + + @Override + public String getServiceName() { + return "Catalina"; + } + + @Override + public boolean hasLoggingConfig() { + return true; + } + + @Override + public InputStream getResourceAsStream(final String resource) { + if ("logging.properties".equals(resource)) { + return new ByteArrayInputStream(EMPTY_BYTES); + } + return null; + } + } } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index c1726e38d0..f13e29fafd 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -128,6 +128,11 @@ MemoryUserDatabase.save(). Deprecate and discontinue use of MemoryUser, MemoryRole, and MemoryGroup classes. (schultz) </fix> + <fix> + <bug>66184</bug>: Ensure that JULI root loggers have a default level of + <code>INFO</code>. Pull request <pr>533</pr> provided by Piotr P. + Karwasz. (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org