Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions java/org/apache/juli/ClassLoaderLogManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,10 @@ protected synchronized void readConfiguration(ClassLoader classLoader)
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
Expand Down
61 changes: 61 additions & 0 deletions test/org/apache/juli/TestClassLoaderLogManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@
*/
package org.apache.juli;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

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;

Expand All @@ -30,6 +38,8 @@
*/
public class TestClassLoaderLogManager {

private static final byte[] EMPTY_BYTES = {};

@Test
public void testReplace() {
ClassLoaderLogManager logManager = new ClassLoaderLogManager();
Expand Down Expand Up @@ -81,6 +91,26 @@ public void testBug56082() {
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("");
assertNotNull("root logger is null", rootLogger);
assertNull("root logger has a parent", rootLogger.getParent());
assertEquals(Level.INFO, rootLogger.getLevel());
} finally {
Thread.currentThread().setContextClassLoader(oldCL);
}
}

private static class LoggerCreateThread extends Thread {

private final LogManager logManager;
Expand Down Expand Up @@ -133,4 +163,35 @@ public void setRunning(boolean running) {
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;
}
}
}