diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/Slf4JLoggingSystem.java b/spring-boot/src/main/java/org/springframework/boot/logging/Slf4JLoggingSystem.java index ca9796d3db0..d9f6834c6d9 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/Slf4JLoggingSystem.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/Slf4JLoggingSystem.java @@ -46,7 +46,7 @@ public abstract class Slf4JLoggingSystem extends AbstractLoggingSystem { private void configureJdkLoggingBridgeHandler() { try { - if (bridgeHandlerIsAvailable()) { + if (isBridgeHandlerAvailable()) { removeJdkLoggingBridgeHandler(); SLF4JBridgeHandler.install(); } @@ -56,13 +56,13 @@ public abstract class Slf4JLoggingSystem extends AbstractLoggingSystem { } } - private boolean bridgeHandlerIsAvailable() { + protected final boolean isBridgeHandlerAvailable() { return ClassUtils.isPresent(BRIDGE_HANDLER, getClassLoader()); } private void removeJdkLoggingBridgeHandler() { try { - if (bridgeHandlerIsAvailable()) { + if (isBridgeHandlerAvailable()) { try { SLF4JBridgeHandler.removeHandlersForRootLogger(); } diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java b/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java index 4756be24860..6f7369e382c 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java @@ -37,6 +37,7 @@ import org.springframework.util.StringUtils; import ch.qos.logback.classic.Level; import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.jul.LevelChangePropagator; import ch.qos.logback.classic.turbo.TurboFilter; import ch.qos.logback.classic.util.ContextInitializer; import ch.qos.logback.core.spi.FilterReply; @@ -99,8 +100,7 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem { @Override protected void loadDefaults(LogFile logFile) { LoggerContext context = getLoggerContext(); - context.stop(); - context.reset(); + stopAndReset(context); LogbackConfigurator configurator = new LogbackConfigurator(context); new DefaultLogbackConfiguration(logFile).apply(configurator); } @@ -112,8 +112,7 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem { logFile.applyToSystemProperties(); } LoggerContext context = getLoggerContext(); - context.stop(); - context.reset(); + stopAndReset(context); try { URL url = ResourceUtils.getURL(location); new ContextInitializer(context).configureByResource(url); @@ -124,6 +123,21 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem { } } + private void stopAndReset(LoggerContext loggerContext) { + loggerContext.stop(); + loggerContext.reset(); + if (isBridgeHandlerAvailable()) { + addLevelChangePropagator(loggerContext); + } + } + + private void addLevelChangePropagator(LoggerContext loggerContext) { + LevelChangePropagator levelChangePropagator = new LevelChangePropagator(); + levelChangePropagator.setResetJUL(true); + levelChangePropagator.setContext(loggerContext); + loggerContext.addListener(levelChangePropagator); + } + @Override protected void reinitialize() { getLoggerContext().reset(); diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java index d48299e1e81..bb2e66b351c 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java @@ -146,6 +146,18 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { assertTrue("Wrong output:\n" + output, output.contains("Hello world")); } + @Test + public void loggingLevelIsPropagatedToJulI() { + this.loggingSystem.beforeInitialize(); + this.loggingSystem.initialize(null, null); + this.loggingSystem.setLogLevel(getClass().getName(), LogLevel.DEBUG); + java.util.logging.Logger julLogger = java.util.logging.Logger + .getLogger(getClass().getName()); + julLogger.fine("Hello debug world"); + String output = this.output.toString().trim(); + assertTrue("Wrong output:\n" + output, output.contains("Hello debug world")); + } + @Test public void jbossLoggingIsConfiguredToUseSlf4j() { this.loggingSystem.beforeInitialize();