From 2ea4d4b1d9d17a6a62f3db6246040eff99caac06 Mon Sep 17 00:00:00 2001 From: Chaouki Dhib Date: Tue, 13 Dec 2016 23:58:28 +0100 Subject: [PATCH] Broaden LoggingApplicationListener ignores Update `LoggingApplicationListener` to ignore all `-D` prefixed property values. As well as catching the Azure use-case, this update now means Spring Boot application can start when Tomcat is missing `CATALINA_BASE\conf\logging.properties` and sets the value `-Dnop`. Closes gh-7639 --- .../boot/logging/LoggingApplicationListener.java | 7 +------ .../logging/LoggingApplicationListenerTests.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java index 01ac287e04..3a6fdbe53e 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java @@ -314,12 +314,7 @@ public class LoggingApplicationListener implements GenericApplicationListener { } private boolean ignoreLogConfig(String logConfig) { - return !StringUtils.hasLength(logConfig) - || isDefaultAzureLoggingConfig(logConfig); - } - - private boolean isDefaultAzureLoggingConfig(String candidate) { - return candidate.startsWith("-Djava.util.logging.config.file="); + return !StringUtils.hasLength(logConfig) || logConfig.startsWith("-D"); } private void initializeFinalLoggingLevels(ConfigurableEnvironment environment, diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java index 6378cbee5d..92536c1f27 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java @@ -162,6 +162,18 @@ public class LoggingApplicationListenerTests { assertThat(new File(tmpDir() + "/spring.log").exists()).isFalse(); } + @Test + public void tomcatNopLoggingConfigDoesNotCauseAFailure() throws Exception { + TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, + "logging.config: -Dnop"); + this.initializer.initialize(this.context.getEnvironment(), + this.context.getClassLoader()); + this.logger.info("Hello world"); + String output = this.outputCapture.toString().trim(); + assertThat(output).contains("Hello world").doesNotContain("???"); + assertThat(new File(tmpDir() + "/spring.log").exists()).isFalse(); + } + @Test public void overrideConfigBroken() throws Exception { TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,