Skip to content

Commit c3ddfcd

Browse files
committed
Trim trailing whitespace from value of logging.config
Closes gh-22078
1 parent d12b6b3 commit c3ddfcd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ private boolean isSet(ConfigurableEnvironment environment, String property) {
301301

302302
private void initializeSystem(ConfigurableEnvironment environment, LoggingSystem system, LogFile logFile) {
303303
LoggingInitializationContext initializationContext = new LoggingInitializationContext(environment);
304-
String logConfig = environment.getProperty(CONFIG_PROPERTY);
304+
String logConfig = StringUtils.trimWhitespace(environment.getProperty(CONFIG_PROPERTY));
305305
if (ignoreLogConfig(logConfig)) {
306306
system.initialize(initializationContext, null, logFile);
307307
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ void overrideConfigLocation() {
160160
assertThat(this.output).contains("Hello world").doesNotContain("???").startsWith("null ").endsWith("BOOTBOOT");
161161
}
162162

163+
@Test
164+
void trailingWhitespaceInLoggingConfigShouldBeTrimmed() {
165+
addPropertiesToEnvironment(this.context, "logging.config=classpath:logback-nondefault.xml ");
166+
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
167+
this.logger.info("Hello world");
168+
assertThat(this.output).contains("Hello world").doesNotContain("???").startsWith("null ").endsWith("BOOTBOOT");
169+
}
170+
163171
@Test
164172
void overrideConfigDoesNotExist() {
165173
addPropertiesToEnvironment(this.context, "logging.config=doesnotexist.xml");

0 commit comments

Comments
 (0)