From d493d3afe79337f36b956c1a47245893da390edf Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Fri, 18 Dec 2015 14:46:11 +0000 Subject: [PATCH] Make Log4J logging system consistent with the others when the logname is empty it replaces it with the root logger name. Fixes gh-4808 --- .../springframework/boot/logging/java/JavaLoggingSystem.java | 3 ++- .../boot/logging/log4j2/Log4J2LoggingSystem.java | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/java/JavaLoggingSystem.java b/spring-boot/src/main/java/org/springframework/boot/logging/java/JavaLoggingSystem.java index 9726f5c8bd..8326ceb67b 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/java/JavaLoggingSystem.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/java/JavaLoggingSystem.java @@ -111,7 +111,8 @@ public class JavaLoggingSystem extends AbstractLoggingSystem { @Override public void setLogLevel(String loggerName, LogLevel level) { Assert.notNull(level, "Level must not be null"); - Logger logger = Logger.getLogger(loggerName == null ? "" : loggerName); + Logger logger = Logger + .getLogger(StringUtils.hasText(loggerName) ? loggerName : ""); logger.setLevel(LEVELS.get(level)); } diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java b/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java index 35b7cf6ba0..60f56ed7bc 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java @@ -46,6 +46,7 @@ import org.springframework.boot.logging.Slf4JLoggingSystem; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ResourceUtils; +import org.springframework.util.StringUtils; /** * {@link LoggingSystem} for Log4j 2. @@ -208,6 +209,8 @@ public class Log4J2LoggingSystem extends Slf4JLoggingSystem { } private LoggerConfig getLoggerConfig(String loggerName) { + loggerName = StringUtils.hasText(loggerName) ? loggerName + : LogManager.ROOT_LOGGER_NAME; return getLoggerContext().getConfiguration().getLoggers().get(loggerName); }