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 3a050486ac..cf2aac58f4 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 @@ -130,13 +130,13 @@ public class Log4J2LoggingSystem extends Slf4JLoggingSystem { @Override public void beforeInitialize() { super.beforeInitialize(); - getRootLoggerConfig().addFilter(FILTER); + getLoggerContext().getConfiguration().addFilter(FILTER); } @Override public void initialize(LoggingInitializationContext initializationContext, String configLocation, LogFile logFile) { - getRootLoggerConfig().removeFilter(FILTER); + getLoggerContext().getConfiguration().removeFilter(FILTER); super.initialize(initializationContext, configLocation, logFile); } @@ -204,10 +204,6 @@ public class Log4J2LoggingSystem extends Slf4JLoggingSystem { return new ShutdownHandler(); } - private LoggerConfig getRootLoggerConfig() { - return getLoggerContext().getConfiguration().getLoggerConfig(""); - } - private LoggerConfig getLoggerConfig(String name) { name = (StringUtils.hasText(name) ? name : LogManager.ROOT_LOGGER_NAME); return getLoggerContext().getConfiguration().getLoggers().get(name); diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java index ed6ca0366d..c602414d3e 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java @@ -209,6 +209,13 @@ public class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests { assertThat(fileContents, is(expectedOutput)); } + @Test + public void beforeInitializeFilterDisablesErrorLogging() throws Exception { + this.loggingSystem.beforeInitialize(); + assertFalse(this.logger.isErrorEnabled()); + this.loggingSystem.initialize(null, null, getLogFile(null, tmpDir())); + } + @Test public void customExceptionConversionWord() throws Exception { System.setProperty("LOG_EXCEPTION_CONVERSION_WORD", "%ex");