Commit f07daf89 authored by Andy Wilkinson's avatar Andy Wilkinson

Merge pull request #12071 from imgx64

* gh-12071:
  Polish "Suppress debug log output during Logback initialization"
  Suppress debug log output during Logback initialization
parents b559cadd 1fc2eba9
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -111,8 +111,8 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem { ...@@ -111,8 +111,8 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
if (isAlreadyInitialized(loggerContext)) { if (isAlreadyInitialized(loggerContext)) {
return; return;
} }
loggerContext.getTurboFilterList().remove(FILTER);
super.initialize(initializationContext, configLocation, logFile); super.initialize(initializationContext, configLocation, logFile);
loggerContext.getTurboFilterList().remove(FILTER);
markAsInitialized(loggerContext); markAsInitialized(loggerContext);
if (StringUtils.hasText(System.getProperty(CONFIGURATION_FILE_PROPERTY))) { if (StringUtils.hasText(System.getProperty(CONFIGURATION_FILE_PROPERTY))) {
getLogger(LogbackLoggingSystem.class.getName()).warn( getLogger(LogbackLoggingSystem.class.getName()).warn(
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -35,10 +35,13 @@ import org.junit.After; ...@@ -35,10 +35,13 @@ import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.ILoggerFactory; import org.slf4j.ILoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler; import org.slf4j.bridge.SLF4JBridgeHandler;
import org.slf4j.impl.StaticLoggerBinder; 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.AbstractLoggingSystemTests;
import org.springframework.boot.logging.LogFile; import org.springframework.boot.logging.LogFile;
import org.springframework.boot.logging.LogLevel; import org.springframework.boot.logging.LogLevel;
...@@ -67,6 +70,8 @@ import static org.mockito.Mockito.verify; ...@@ -67,6 +70,8 @@ import static org.mockito.Mockito.verify;
* @author Ben Hale * @author Ben Hale
* @author Madhura Bhave * @author Madhura Bhave
*/ */
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions("log4j-*.jar")
public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
@Rule @Rule
...@@ -132,13 +137,15 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests { ...@@ -132,13 +137,15 @@ public class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
} }
@Test @Test
public void testNonDefaultConfigLocation() throws Exception { public void testNonDefaultConfigLocation() {
int existingOutputLength = this.output.toString().length();
this.loggingSystem.beforeInitialize(); this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(this.initializationContext, this.loggingSystem.initialize(this.initializationContext,
"classpath:logback-nondefault.xml", "classpath:logback-nondefault.xml",
getLogFile(tmpDir() + "/tmp.log", null)); getLogFile(tmpDir() + "/tmp.log", null));
this.logger.info("Hello world"); this.logger.info("Hello world");
String output = this.output.toString().trim(); String output = this.output.toString().trim();
assertThat(output.substring(existingOutputLength)).doesNotContain("DEBUG");
assertThat(output).contains("Hello world").contains(tmpDir() + "/tmp.log"); assertThat(output).contains("Hello world").contains(tmpDir() + "/tmp.log");
assertThat(output).endsWith("BOOTBOOT"); assertThat(output).endsWith("BOOTBOOT");
assertThat(new File(tmpDir() + "/tmp.log").exists()).isFalse(); assertThat(new File(tmpDir() + "/tmp.log").exists()).isFalse();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment