Skip to content

Commit ffdca41

Browse files
committed
web and sql groups are being expanded to the logger names that each represents.
gh-15986
1 parent c44a1e1 commit ffdca41

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121
import java.util.List;
2222
import java.util.Locale;
2323
import java.util.Map;
24+
import java.util.Optional;
2425
import java.util.concurrent.atomic.AtomicBoolean;
2526

2627
import org.apache.commons.logging.Log;
@@ -320,12 +321,11 @@ private void initializeFinalLoggingLevels(ConfigurableEnvironment environment,
320321
}
321322

322323
protected void initializeLogLevel(LoggingSystem system, LogLevel level) {
323-
List<String> loggers = LOG_LEVEL_LOGGERS.get(level);
324-
if (loggers != null) {
325-
for (String logger : loggers) {
326-
system.setLogLevel(logger, level);
327-
}
328-
}
324+
Optional.ofNullable(LOG_LEVEL_LOGGERS.get(level)).orElse(Collections.emptyList())
325+
.stream()
326+
.flatMap((logger) -> DEFAULT_GROUP_LOGGERS
327+
.getOrDefault(logger, Collections.singletonList(logger)).stream())
328+
.forEach((logger) -> system.setLogLevel(logger, level));
329329
}
330330

331331
protected void setLogLevels(LoggingSystem system, Environment environment) {

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -315,6 +315,21 @@ public void parseDebugArg() {
315315
assertThat(this.outputCapture.toString()).doesNotContain("testattrace");
316316
}
317317

318+
@Test
319+
public void parseDebugArgExpandGroups() {
320+
addPropertiesToEnvironment(this.context, "debug");
321+
this.initializer.initialize(this.context.getEnvironment(),
322+
this.context.getClassLoader());
323+
ch.qos.logback.classic.Logger sqlGroup = this.loggerContext
324+
.getLogger("org.hibernate.SQL");
325+
ch.qos.logback.classic.Logger webGroup = this.loggerContext
326+
.getLogger("org.springframework.boot.actuate.endpoint.web");
327+
webGroup.debug("testdebugwebgroup");
328+
sqlGroup.debug("testdebugsqlgroup");
329+
assertThat(this.outputCapture.toString()).contains("testdebugwebgroup");
330+
assertThat(this.outputCapture.toString()).contains("testdebugsqlgroup");
331+
}
332+
318333
@Test
319334
public void parseTraceArg() {
320335
addPropertiesToEnvironment(this.context, "trace");

0 commit comments

Comments
 (0)