Skip to content

Commit 2ea4d4b

Browse files
chaodhibphilwebb
authored andcommitted
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
1 parent f36ed67 commit 2ea4d4b

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,7 @@ private void initializeSystem(ConfigurableEnvironment environment,
314314
}
315315

316316
private boolean ignoreLogConfig(String logConfig) {
317-
return !StringUtils.hasLength(logConfig)
318-
|| isDefaultAzureLoggingConfig(logConfig);
319-
}
320-
321-
private boolean isDefaultAzureLoggingConfig(String candidate) {
322-
return candidate.startsWith("-Djava.util.logging.config.file=");
317+
return !StringUtils.hasLength(logConfig) || logConfig.startsWith("-D");
323318
}
324319

325320
private void initializeFinalLoggingLevels(ConfigurableEnvironment environment,

spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ public void azureDefaultLoggingConfigDoesNotCauseAFailure() throws Exception {
162162
assertThat(new File(tmpDir() + "/spring.log").exists()).isFalse();
163163
}
164164

165+
@Test
166+
public void tomcatNopLoggingConfigDoesNotCauseAFailure() throws Exception {
167+
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
168+
"logging.config: -Dnop");
169+
this.initializer.initialize(this.context.getEnvironment(),
170+
this.context.getClassLoader());
171+
this.logger.info("Hello world");
172+
String output = this.outputCapture.toString().trim();
173+
assertThat(output).contains("Hello world").doesNotContain("???");
174+
assertThat(new File(tmpDir() + "/spring.log").exists()).isFalse();
175+
}
176+
165177
@Test
166178
public void overrideConfigBroken() throws Exception {
167179
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,

0 commit comments

Comments
 (0)