From 8f44bb9d42353f0e27c9a26b15f85d82709749ad Mon Sep 17 00:00:00 2001 From: imgx64 Date: Thu, 15 Feb 2018 11:35:37 +0300 Subject: [PATCH 1/2] Suppress debug log output during Logback initialization Closes gh-12071 --- .../boot/logging/logback/LogbackLoggingSystem.java | 2 +- .../boot/logging/logback/LogbackLoggingSystemTests.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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 4a4dd3d259..8b076f3f5a 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 @@ -111,8 +111,8 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem { if (isAlreadyInitialized(loggerContext)) { return; } - loggerContext.getTurboFilterList().remove(FILTER); super.initialize(initializationContext, configLocation, logFile); + loggerContext.getTurboFilterList().remove(FILTER); markAsInitialized(loggerContext); if (StringUtils.hasText(System.getProperty(CONFIGURATION_FILE_PROPERTY))) { getLogger(LogbackLoggingSystem.class.getName()).warn( 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 e1230eb98d..5e849252d1 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 @@ -35,10 +35,13 @@ import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; import org.slf4j.ILoggerFactory; import org.slf4j.bridge.SLF4JBridgeHandler; import org.slf4j.impl.StaticLoggerBinder; +import org.springframework.boot.junit.runner.classpath.ClassPathExclusions; +import org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner; import org.springframework.boot.logging.AbstractLoggingSystemTests; import org.springframework.boot.logging.LogFile; import org.springframework.boot.logging.LogLevel; @@ -67,6 +70,8 @@ import static org.mockito.Mockito.verify; * @author Ben Hale * @author Madhura Bhave */ +@RunWith(ModifiedClassPathRunner.class) +@ClassPathExclusions("log4j-*.jar") public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { @Rule @@ -133,12 +138,14 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { @Test public void testNonDefaultConfigLocation() throws Exception { + int existingOutputLength = this.output.toString().length(); this.loggingSystem.beforeInitialize(); this.loggingSystem.initialize(this.initializationContext, "classpath:logback-nondefault.xml", getLogFile(tmpDir() + "/tmp.log", null)); this.logger.info("Hello world"); String output = this.output.toString().trim(); + assertThat(output.substring(existingOutputLength)).doesNotContain("DEBUG"); assertThat(output).contains("Hello world").contains(tmpDir() + "/tmp.log"); assertThat(output).endsWith("BOOTBOOT"); assertThat(new File(tmpDir() + "/tmp.log").exists()).isFalse(); From 1fc2eba98b258e425191638c31168e5167ab0073 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 14 May 2018 17:58:59 +0100 Subject: [PATCH 2/2] Polish "Suppress debug log output during Logback initialization" See gh-12071 --- .../boot/logging/logback/LogbackLoggingSystem.java | 2 +- .../boot/logging/logback/LogbackLoggingSystemTests.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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 8b076f3f5a..3e3fef8df5 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 5e849252d1..d008f4c21e 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -137,7 +137,7 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { } @Test - public void testNonDefaultConfigLocation() throws Exception { + public void testNonDefaultConfigLocation() { int existingOutputLength = this.output.toString().length(); this.loggingSystem.beforeInitialize(); this.loggingSystem.initialize(this.initializationContext,