Skip to content

Commit

Permalink
web and sql groups are being expanded to the logger names that each r…
Browse files Browse the repository at this point in the history
…epresents.

gh-15986
  • Loading branch information
nosan committed Feb 22, 2019
1 parent adea701 commit a001e28
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -320,12 +321,11 @@ private void initializeFinalLoggingLevels(ConfigurableEnvironment environment,
}

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

protected void setLogLevels(LoggingSystem system, Environment environment) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -315,6 +315,21 @@ public void parseDebugArg() {
assertThat(this.outputCapture.toString()).doesNotContain("testattrace");
}

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

@Test
public void parseTraceArg() {
addPropertiesToEnvironment(this.context, "trace");
Expand Down

0 comments on commit a001e28

Please sign in to comment.