From d194b7f3c00fb16f924e583dac181ce24b4f658c Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Tue, 9 Apr 2024 11:13:37 +0200 Subject: [PATCH 1/2] Replace custom filter with DenyAllFilter See gh-40235 --- .../logging/log4j2/Log4J2LoggingSystem.java | 29 ++----------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java index 1ff7c840ed0..f02e3f72c90 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java @@ -31,9 +31,7 @@ import java.util.logging.Handler; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.core.Filter; -import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.Logger; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.config.AbstractConfiguration; @@ -42,14 +40,13 @@ import org.apache.logging.log4j.core.config.ConfigurationFactory; import org.apache.logging.log4j.core.config.ConfigurationSource; import org.apache.logging.log4j.core.config.LoggerConfig; import org.apache.logging.log4j.core.config.composite.CompositeConfiguration; -import org.apache.logging.log4j.core.filter.AbstractFilter; +import org.apache.logging.log4j.core.filter.DenyAllFilter; import org.apache.logging.log4j.core.net.UrlConnectionFactory; import org.apache.logging.log4j.core.net.ssl.SslConfiguration; import org.apache.logging.log4j.core.net.ssl.SslConfigurationFactory; import org.apache.logging.log4j.core.util.AuthorizationProvider; import org.apache.logging.log4j.core.util.NameUtil; import org.apache.logging.log4j.jul.Log4jBridgeHandler; -import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.util.PropertiesUtil; import org.springframework.boot.context.properties.bind.BindResult; @@ -106,29 +103,7 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem { LEVELS.map(LogLevel.OFF, Level.OFF); } - private static final Filter FILTER = new AbstractFilter() { - - @Override - public Result filter(LogEvent event) { - return Result.DENY; - } - - @Override - public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) { - return Result.DENY; - } - - @Override - public Result filter(Logger logger, Level level, Marker marker, Object msg, Throwable t) { - return Result.DENY; - } - - @Override - public Result filter(Logger logger, Level level, Marker marker, String msg, Object... params) { - return Result.DENY; - } - - }; + private static final Filter FILTER = DenyAllFilter.newBuilder().build(); public Log4J2LoggingSystem(ClassLoader classLoader) { super(classLoader); From ef9f1b41d7c98cc1aef463713178eeef0edf07fb Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 10 Apr 2024 19:44:45 +0100 Subject: [PATCH 2/2] Polish "Replace custom filter with DenyAllFilter" See gh-40235 --- .../boot/logging/log4j2/Log4J2LoggingSystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java index f02e3f72c90..4d7c8b0629b 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 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.