Commit fa1ff72f authored by Phillip Webb's avatar Phillip Webb

Restore quiet logging on startup

Reinstate initializeWithSensibleDefaults() on AbstractLoggingSystem
beforeInitialize(). This is required to ensure no superfluous logging
output occurs when starting up a spring boot application from the
command line.

It appears that commit e9c649df
modified the logic in an attempt to prevent double initialization.

fixes gh-174
parent cd1a2282
...@@ -42,6 +42,7 @@ public abstract class AbstractLoggingSystem extends LoggingSystem { ...@@ -42,6 +42,7 @@ public abstract class AbstractLoggingSystem extends LoggingSystem {
@Override @Override
public void beforeInitialize() { public void beforeInitialize() {
initializeWithSensibleDefaults();
} }
@Override @Override
...@@ -53,7 +54,6 @@ public abstract class AbstractLoggingSystem extends LoggingSystem { ...@@ -53,7 +54,6 @@ public abstract class AbstractLoggingSystem extends LoggingSystem {
return; return;
} }
} }
initializeWithSensibleDefaults();
} }
protected void initializeWithSensibleDefaults() { protected void initializeWithSensibleDefaults() {
......
...@@ -61,6 +61,7 @@ public class JavaLoggerSystemTests { ...@@ -61,6 +61,7 @@ public class JavaLoggerSystemTests {
@Test @Test
public void testCustomFormatter() throws Exception { public void testCustomFormatter() throws Exception {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(); this.loggingSystem.initialize();
this.logger.info("Hello world"); this.logger.info("Hello world");
String output = this.output.toString().trim(); String output = this.output.toString().trim();
...@@ -71,6 +72,7 @@ public class JavaLoggerSystemTests { ...@@ -71,6 +72,7 @@ public class JavaLoggerSystemTests {
@Test @Test
public void testSystemPropertyInitializesFormat() throws Exception { public void testSystemPropertyInitializesFormat() throws Exception {
System.setProperty("PID", "1234"); System.setProperty("PID", "1234");
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize("classpath:" this.loggingSystem.initialize("classpath:"
+ ClassUtils.addResourcePathToPackagePath(getClass(), + ClassUtils.addResourcePathToPackagePath(getClass(),
"logging.properties")); "logging.properties"));
...@@ -83,6 +85,7 @@ public class JavaLoggerSystemTests { ...@@ -83,6 +85,7 @@ public class JavaLoggerSystemTests {
@Test @Test
public void testNonDefaultConfigLocation() throws Exception { public void testNonDefaultConfigLocation() throws Exception {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize("classpath:logging-nondefault.properties"); this.loggingSystem.initialize("classpath:logging-nondefault.properties");
this.logger.info("Hello world"); this.logger.info("Hello world");
String output = this.output.toString().trim(); String output = this.output.toString().trim();
...@@ -91,16 +94,19 @@ public class JavaLoggerSystemTests { ...@@ -91,16 +94,19 @@ public class JavaLoggerSystemTests {
@Test(expected = IllegalStateException.class) @Test(expected = IllegalStateException.class)
public void testNonexistentConfigLocation() throws Exception { public void testNonexistentConfigLocation() throws Exception {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize("classpath:logging-nonexistent.properties"); this.loggingSystem.initialize("classpath:logging-nonexistent.properties");
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void testNullConfigLocation() throws Exception { public void testNullConfigLocation() throws Exception {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(null); this.loggingSystem.initialize(null);
} }
@Test @Test
public void setLevel() throws Exception { public void setLevel() throws Exception {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(); this.loggingSystem.initialize();
this.logger.debug("Hello"); this.logger.debug("Hello");
this.loggingSystem.setLogLevel("org.springframework.boot", LogLevel.DEBUG); this.loggingSystem.setLogLevel("org.springframework.boot", LogLevel.DEBUG);
......
...@@ -58,6 +58,7 @@ public class Log4JLoggingSystemTests { ...@@ -58,6 +58,7 @@ public class Log4JLoggingSystemTests {
@Test @Test
public void testNonDefaultConfigLocation() throws Exception { public void testNonDefaultConfigLocation() throws Exception {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize("classpath:log4j-nondefault.properties"); this.loggingSystem.initialize("classpath:log4j-nondefault.properties");
this.logger.info("Hello world"); this.logger.info("Hello world");
String output = this.output.toString().trim(); String output = this.output.toString().trim();
...@@ -67,16 +68,19 @@ public class Log4JLoggingSystemTests { ...@@ -67,16 +68,19 @@ public class Log4JLoggingSystemTests {
@Test(expected = IllegalStateException.class) @Test(expected = IllegalStateException.class)
public void testNonexistentConfigLocation() throws Exception { public void testNonexistentConfigLocation() throws Exception {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize("classpath:log4j-nonexistent.xml"); this.loggingSystem.initialize("classpath:log4j-nonexistent.xml");
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void testNullConfigLocation() throws Exception { public void testNullConfigLocation() throws Exception {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(null); this.loggingSystem.initialize(null);
} }
@Test @Test
public void setLevel() throws Exception { public void setLevel() throws Exception {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(); this.loggingSystem.initialize();
this.logger.debug("Hello"); this.logger.debug("Hello");
this.loggingSystem.setLogLevel("org.springframework.boot", LogLevel.DEBUG); this.loggingSystem.setLogLevel("org.springframework.boot", LogLevel.DEBUG);
......
...@@ -59,6 +59,7 @@ public class LogbackLoggingSystemTests { ...@@ -59,6 +59,7 @@ public class LogbackLoggingSystemTests {
@Test @Test
public void testNonDefaultConfigLocation() throws Exception { public void testNonDefaultConfigLocation() throws Exception {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize("classpath:logback-nondefault.xml"); this.loggingSystem.initialize("classpath:logback-nondefault.xml");
this.logger.info("Hello world"); this.logger.info("Hello world");
String output = this.output.toString().trim(); String output = this.output.toString().trim();
...@@ -68,16 +69,19 @@ public class LogbackLoggingSystemTests { ...@@ -68,16 +69,19 @@ public class LogbackLoggingSystemTests {
@Test(expected = IllegalStateException.class) @Test(expected = IllegalStateException.class)
public void testNonexistentConfigLocation() throws Exception { public void testNonexistentConfigLocation() throws Exception {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize("classpath:logback-nonexistent.xml"); this.loggingSystem.initialize("classpath:logback-nonexistent.xml");
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void testNullConfigLocation() throws Exception { public void testNullConfigLocation() throws Exception {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(null); this.loggingSystem.initialize(null);
} }
@Test @Test
public void setLevel() throws Exception { public void setLevel() throws Exception {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(); this.loggingSystem.initialize();
this.logger.debug("Hello"); this.logger.debug("Hello");
this.loggingSystem.setLogLevel("org.springframework.boot", LogLevel.DEBUG); this.loggingSystem.setLogLevel("org.springframework.boot", LogLevel.DEBUG);
......
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