Polish "Debug mode is not logging web and sql related loggers"

Closes gh-16018
This commit is contained in:
Stephane Nicoll 2019-02-27 13:37:18 +01:00
parent c3430d5883
commit 978f80122b
2 changed files with 5 additions and 10 deletions

View File

@ -21,7 +21,6 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -321,8 +320,7 @@ public class LoggingApplicationListener implements GenericApplicationListener {
} }
protected void initializeLogLevel(LoggingSystem system, LogLevel level) { protected void initializeLogLevel(LoggingSystem system, LogLevel level) {
Optional.ofNullable(LOG_LEVEL_LOGGERS.get(level)).orElse(Collections.emptyList()) LOG_LEVEL_LOGGERS.getOrDefault(level, Collections.emptyList()).stream()
.stream()
.flatMap((logger) -> DEFAULT_GROUP_LOGGERS .flatMap((logger) -> DEFAULT_GROUP_LOGGERS
.getOrDefault(logger, Collections.singletonList(logger)).stream()) .getOrDefault(logger, Collections.singletonList(logger)).stream())
.forEach((logger) -> system.setLogLevel(logger, level)); .forEach((logger) -> system.setLogLevel(logger, level));

View File

@ -264,15 +264,12 @@ public class LoggingApplicationListenerTests {
@Test @Test
public void parseDebugArgExpandGroups() { public void parseDebugArgExpandGroups() {
addPropertiesToEnvironment(this.context, "debug"); TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "debug");
this.initializer.initialize(this.context.getEnvironment(), this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader()); this.context.getClassLoader());
ch.qos.logback.classic.Logger sqlGroup = this.loggerContext this.logFactory.getInstance("org.springframework.boot.actuate.endpoint.web")
.getLogger("org.hibernate.SQL"); .debug("testdebugwebgroup");
ch.qos.logback.classic.Logger webGroup = this.loggerContext this.logFactory.getInstance("org.hibernate.SQL").debug("testdebugsqlgroup");
.getLogger("org.springframework.boot.actuate.endpoint.web");
webGroup.debug("testdebugwebgroup");
sqlGroup.debug("testdebugsqlgroup");
assertThat(this.outputCapture.toString()).contains("testdebugwebgroup"); assertThat(this.outputCapture.toString()).contains("testdebugwebgroup");
assertThat(this.outputCapture.toString()).contains("testdebugsqlgroup"); assertThat(this.outputCapture.toString()).contains("testdebugsqlgroup");
} }