Skip to content

Commit f07daf8

Browse files
committed
Merge pull request #12071 from imgx64
* gh-12071: Polish "Suppress debug log output during Logback initialization" Suppress debug log output during Logback initialization
2 parents b559cad + 1fc2eba commit f07daf8

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -111,8 +111,8 @@ public void initialize(LoggingInitializationContext initializationContext,
111111
if (isAlreadyInitialized(loggerContext)) {
112112
return;
113113
}
114-
loggerContext.getTurboFilterList().remove(FILTER);
115114
super.initialize(initializationContext, configLocation, logFile);
115+
loggerContext.getTurboFilterList().remove(FILTER);
116116
markAsInitialized(loggerContext);
117117
if (StringUtils.hasText(System.getProperty(CONFIGURATION_FILE_PROPERTY))) {
118118
getLogger(LogbackLoggingSystem.class.getName()).warn(

spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,10 +35,13 @@
3535
import org.junit.Before;
3636
import org.junit.Rule;
3737
import org.junit.Test;
38+
import org.junit.runner.RunWith;
3839
import org.slf4j.ILoggerFactory;
3940
import org.slf4j.bridge.SLF4JBridgeHandler;
4041
import org.slf4j.impl.StaticLoggerBinder;
4142

43+
import org.springframework.boot.junit.runner.classpath.ClassPathExclusions;
44+
import org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner;
4245
import org.springframework.boot.logging.AbstractLoggingSystemTests;
4346
import org.springframework.boot.logging.LogFile;
4447
import org.springframework.boot.logging.LogLevel;
@@ -67,6 +70,8 @@
6770
* @author Ben Hale
6871
* @author Madhura Bhave
6972
*/
73+
@RunWith(ModifiedClassPathRunner.class)
74+
@ClassPathExclusions("log4j-*.jar")
7075
public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
7176

7277
@Rule
@@ -132,13 +137,15 @@ public void testBasicConfigLocation() throws Exception {
132137
}
133138

134139
@Test
135-
public void testNonDefaultConfigLocation() throws Exception {
140+
public void testNonDefaultConfigLocation() {
141+
int existingOutputLength = this.output.toString().length();
136142
this.loggingSystem.beforeInitialize();
137143
this.loggingSystem.initialize(this.initializationContext,
138144
"classpath:logback-nondefault.xml",
139145
getLogFile(tmpDir() + "/tmp.log", null));
140146
this.logger.info("Hello world");
141147
String output = this.output.toString().trim();
148+
assertThat(output.substring(existingOutputLength)).doesNotContain("DEBUG");
142149
assertThat(output).contains("Hello world").contains(tmpDir() + "/tmp.log");
143150
assertThat(output).endsWith("BOOTBOOT");
144151
assertThat(new File(tmpDir() + "/tmp.log").exists()).isFalse();

0 commit comments

Comments
 (0)