Skip to content

Commit 3b2fb30

Browse files
author
Dave Syer
committed
Add placeholder support to LoggingApplicationListener
When logging.level.* is set in external configuration they can now contain placeholders. Fixes gh-1680
1 parent 3135c7f commit 3b2fb30

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public void setLogLevels(LoggingSystem system, Environment environment) {
224224
for (Entry<String, Object> entry : levels.entrySet()) {
225225
String name = entry.getKey();
226226
try {
227-
LogLevel level = LogLevel.valueOf(entry.getValue().toString());
227+
LogLevel level = LogLevel.valueOf(environment.resolvePlaceholders(entry.getValue().toString()));
228228
if (name.equalsIgnoreCase("root")) {
229229
name = null;
230230
}

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
@@ -204,6 +204,18 @@ public void parseLevels() throws Exception {
204204
assertThat(this.outputCapture.toString(), containsString("testattrace"));
205205
}
206206

207+
@Test
208+
public void parseLevelsWithPlaceholder() throws Exception {
209+
EnvironmentTestUtils.addEnvironment(this.context, "foo=TRACE",
210+
"logging.level.org.springframework.boot=${foo}");
211+
this.initializer.initialize(this.context.getEnvironment(),
212+
this.context.getClassLoader());
213+
this.logger.debug("testatdebug");
214+
this.logger.trace("testattrace");
215+
assertThat(this.outputCapture.toString(), containsString("testatdebug"));
216+
assertThat(this.outputCapture.toString(), containsString("testattrace"));
217+
}
218+
207219
@Test
208220
public void parseLevelsFails() throws Exception {
209221
EnvironmentTestUtils.addEnvironment(this.context,

0 commit comments

Comments
 (0)