Skip to content

Commit c3430d5

Browse files
nosansnicoll
authored andcommitted
Debug mode is not logging web and sql related loggers
See gh-16018
1 parent 130ef10 commit c3430d5

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.
@@ -262,6 +262,21 @@ public void parseDebugArg() {
262262
assertThat(this.outputCapture.toString()).doesNotContain("testattrace");
263263
}
264264

265+
@Test
266+
public void parseDebugArgExpandGroups() {
267+
addPropertiesToEnvironment(this.context, "debug");
268+
this.initializer.initialize(this.context.getEnvironment(),
269+
this.context.getClassLoader());
270+
ch.qos.logback.classic.Logger sqlGroup = this.loggerContext
271+
.getLogger("org.hibernate.SQL");
272+
ch.qos.logback.classic.Logger webGroup = this.loggerContext
273+
.getLogger("org.springframework.boot.actuate.endpoint.web");
274+
webGroup.debug("testdebugwebgroup");
275+
sqlGroup.debug("testdebugsqlgroup");
276+
assertThat(this.outputCapture.toString()).contains("testdebugwebgroup");
277+
assertThat(this.outputCapture.toString()).contains("testdebugsqlgroup");
278+
}
279+
265280
@Test
266281
public void parseTraceArg() {
267282
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "trace");

0 commit comments

Comments
 (0)