This is an automated email from the ASF dual-hosted git repository.

rgoers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/master by this push:
     new 724d84ed9e LOG4J2-3506 - Support Spring 2.6.x
724d84ed9e is described below

commit 724d84ed9ea429daacb61f86df273c054c956ae4
Author: Ralph Goers <[email protected]>
AuthorDate: Sun May 15 23:06:31 2022 -0700

    LOG4J2-3506 - Support Spring 2.6.x
---
 ...tem.java => Log4j2SpringBootLoggingSystem.java} | 79 +++++++++++++++-------
 .../log4j/spring/boot/SpringEnvironmentHolder.java |  2 +-
 .../src/main/resources/META-INF/spring.factories   |  2 +-
 .../boot/Log4j2CloudConfigLoggingSystemTest.java   |  6 +-
 .../log4j/spring/boot/SpringLookupTest.java        |  4 +-
 .../log4j/spring/boot/SpringProfileTest.java       |  2 +-
 .../log4j-spring-cloud-config-client/pom.xml       |  5 ++
 .../pom.xml                                        |  7 ++
 pom.xml                                            |  4 +-
 src/changes/changes.xml                            |  5 +-
 10 files changed, 81 insertions(+), 35 deletions(-)

diff --git 
a/log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/Log4j2CloudConfigLoggingSystem.java
 
b/log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/Log4j2SpringBootLoggingSystem.java
similarity index 75%
rename from 
log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/Log4j2CloudConfigLoggingSystem.java
rename to 
log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/Log4j2SpringBootLoggingSystem.java
index 65901b14be..0d9bf1b3a7 100644
--- 
a/log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/Log4j2CloudConfigLoggingSystem.java
+++ 
b/log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/Log4j2SpringBootLoggingSystem.java
@@ -25,7 +25,6 @@ import 
org.apache.logging.log4j.core.config.ConfigurationFactory;
 import org.apache.logging.log4j.core.config.ConfigurationSource;
 import org.apache.logging.log4j.core.config.composite.CompositeConfiguration;
 import org.apache.logging.log4j.core.net.UrlConnectionFactory;
-import org.apache.logging.log4j.core.net.ssl.LaxHostnameVerifier;
 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;
@@ -42,10 +41,10 @@ import org.springframework.util.Assert;
 import org.springframework.util.ClassUtils;
 import org.springframework.util.ResourceUtils;
 
-import javax.net.ssl.HttpsURLConnection;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -54,13 +53,14 @@ import java.net.URLDecoder;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
 
 /**
  * Override Spring's implementation of the Log4j 2 Logging System to properly 
support Spring Cloud Config.
  */
-public class Log4j2CloudConfigLoggingSystem extends Log4J2LoggingSystem {
+public class Log4j2SpringBootLoggingSystem extends Log4J2LoggingSystem {
 
     /**
      * Property that disables the usage of this {@link LoggingSystem}.
@@ -73,7 +73,7 @@ public class Log4j2CloudConfigLoggingSystem extends 
Log4J2LoggingSystem {
     private static final Logger LOGGER = StatusLogger.getLogger();
     private static final int PRECEDENCE = 0;
 
-    public Log4j2CloudConfigLoggingSystem(ClassLoader loader) {
+    public Log4j2SpringBootLoggingSystem(ClassLoader loader) {
         super(loader);
     }
 
@@ -104,6 +104,18 @@ public class Log4j2CloudConfigLoggingSystem extends 
Log4J2LoggingSystem {
         return locations;
     }
 
+    /**
+     * This method is removed from Spring in 3.x and is scheduled to be 
removed in 2.8.x. It must be left in
+     * to support older Spring releases.
+     * @param location the location
+     * @param logFile log file configuration
+     */
+    @Override
+    protected void loadConfiguration(String location, LogFile logFile) {
+        loadConfiguration(location, logFile, Collections.emptyList());
+    }
+
+
     @Override
     protected void loadDefaults(LoggingInitializationContext 
initializationContext, LogFile logFile) {
         if (logFile != null) {
@@ -121,32 +133,52 @@ public class Log4j2CloudConfigLoggingSystem extends 
Log4J2LoggingSystem {
         return defaultPath;
     }
 
+    /**
+     * Added in Spring 2.6.0, the overrides parameter allows override files to 
be specified in the
+     * "logging.log4j2.config.override" property. However, spring does not 
support passing credentials
+     * when accessing the location. We do.
+     * @param location The location of the primary configuration.
+     * @param logFile log file configuration.
+     * @param overrides Any override files.
+     */
     @Override
-    protected void loadConfiguration(String location, LogFile logFile) {
+    protected void loadConfiguration(String location, LogFile logFile, 
List<String> overrides) {
         Assert.notNull(location, "Location must not be null");
         try {
-            final LoggerContext ctx = getLoggerContext();
-            final ConfigurationFactory factory = 
ctx.getInjector().getInstance(ConfigurationFactory.KEY);
-            final String[] locations = parseConfigLocations(location);
-            if (locations.length == 1) {
+            LoggerContext ctx = getLoggerContext();
+            List<String> locations = parseConfigLocations(location);
+            if (overrides != null) {
+                locations.addAll(overrides);
+            }
+            if (locations.size() == 1) {
                 final URL url = ResourceUtils.getURL(location);
                 final ConfigurationSource source = getConfigurationSource(url);
                 if (source != null) {
-                    ctx.start(factory.getConfiguration(ctx, source));
+                    
ctx.start(ConfigurationFactory.getInstance().getConfiguration(ctx, source));
                 }
             } else {
                 final List<AbstractConfiguration> configs = new ArrayList<>();
+                boolean first = true;
                 for (final String sourceLocation : locations) {
                     final ConfigurationSource source = 
getConfigurationSource(ResourceUtils.getURL(sourceLocation));
                     if (source != null) {
-                        final Configuration config = 
factory.getConfiguration(ctx, source);
-                        if (config instanceof AbstractConfiguration) {
-                            configs.add((AbstractConfiguration) config);
-                        } else {
-                            LOGGER.warn("Configuration at {} cannot be 
combined in a CompositeConfiguration", sourceLocation);
-                            return;
+                        try {
+                            final Configuration config = 
ConfigurationFactory.getInstance().getConfiguration(ctx, source);
+                            if (config instanceof AbstractConfiguration) {
+                                configs.add((AbstractConfiguration) config);
+                            } else {
+                                LOGGER.warn("Configuration at {} cannot be 
combined in a CompositeConfiguration", sourceLocation);
+                                return;
+                            }
+                        } catch (Exception ex) {
+                            if (!first) {
+                                LOGGER.warn("Error accessing {}: {}. Ignoring 
override", sourceLocation, ex.getMessage());
+                            } else {
+                                throw ex;
+                            }
                         }
                     }
+                    first = false;
                 }
                 if (configs.size() > 1) {
                     ctx.start(new CompositeConfiguration(configs));
@@ -157,7 +189,7 @@ public class Log4j2CloudConfigLoggingSystem extends 
Log4J2LoggingSystem {
         }
         catch (Exception ex) {
             throw new IllegalStateException(
-                "Could not initialize Log4J2 logging from " + location, ex);
+                    "Could not initialize Log4J2 logging from " + location, 
ex);
         }
     }
 
@@ -167,27 +199,28 @@ public class Log4j2CloudConfigLoggingSystem extends 
Log4J2LoggingSystem {
         super.cleanUp();
     }
 
-    private String[] parseConfigLocations(String configLocations) {
+    private List<String> parseConfigLocations(String configLocations) {
         final String[] uris = configLocations.split("\\?");
         final List<String> locations = new ArrayList<>();
+        locations.add(uris[0]);
         if (uris.length > 1) {
-            locations.add(uris[0]);
             try {
                 final URL url = new URL(configLocations);
                 final String[] pairs = url.getQuery().split("&");
                 for (String pair : pairs) {
                     final int idx = pair.indexOf("=");
-                    final String key = idx > 0 ? 
URLDecoder.decode(pair.substring(0, idx), StandardCharsets.UTF_8) : pair;
+                    final String key = idx > 0 ?
+                            URLDecoder.decode(pair.substring(0, idx), 
StandardCharsets.UTF_8) : pair;
                     if (key.equalsIgnoreCase(OVERRIDE_PARAM)) {
                         locations.add(URLDecoder.decode(pair.substring(idx + 
1), StandardCharsets.UTF_8));
                     }
                 }
-                return locations.toArray(new String[0]);
+                return locations;
             } catch (MalformedURLException ex) {
                 LOGGER.warn("Unable to parse configuration URL {}", 
configLocations);
             }
         }
-        return new String[] {uris[0]};
+        return locations;
     }
 
     private ConfigurationSource getConfigurationSource(URL url) throws 
IOException, URISyntaxException {
@@ -222,7 +255,7 @@ public class Log4j2CloudConfigLoggingSystem extends 
Log4J2LoggingSystem {
             if 
(PropertiesUtil.getProperties().getBooleanProperty(LOG4J2_DISABLE_CLOUD_CONFIG_LOGGING_SYSTEM))
 {
                 return null;
             }
-            return new Log4j2CloudConfigLoggingSystem(classLoader);
+            return new Log4j2SpringBootLoggingSystem(classLoader);
         }
 
     }
diff --git 
a/log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/SpringEnvironmentHolder.java
 
b/log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/SpringEnvironmentHolder.java
index 5c4403ddd5..4091ef6aa3 100644
--- 
a/log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/SpringEnvironmentHolder.java
+++ 
b/log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/SpringEnvironmentHolder.java
@@ -38,7 +38,7 @@ public class SpringEnvironmentHolder {
             lock.lock();
             try {
                 if (environment == null) {
-                    Object obj = 
LogManager.getContext(false).getObject(Log4j2CloudConfigLoggingSystem.ENVIRONMENT_KEY);
+                    Object obj = 
LogManager.getContext(false).getObject(Log4j2SpringBootLoggingSystem.ENVIRONMENT_KEY);
                     environment = obj instanceof Environment ? (Environment) 
obj : null;
                 }
             } finally {
diff --git a/log4j-spring-boot/src/main/resources/META-INF/spring.factories 
b/log4j-spring-boot/src/main/resources/META-INF/spring.factories
index 4ee1569639..c9f555714e 100644
--- a/log4j-spring-boot/src/main/resources/META-INF/spring.factories
+++ b/log4j-spring-boot/src/main/resources/META-INF/spring.factories
@@ -14,4 +14,4 @@
 # See the license for the specific language governing permissions and
 # limitations under the license.
 #
-org.springframework.boot.logging.LoggingSystemFactory=org.apache.logging.log4j.spring.boot.Log4j2CloudConfigLoggingSystem.Factory
\ No newline at end of file
+org.springframework.boot.logging.LoggingSystemFactory=org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.Factory
\ No newline at end of file
diff --git 
a/log4j-spring-boot/src/test/java/org/apache/logging/log4j/spring/boot/Log4j2CloudConfigLoggingSystemTest.java
 
b/log4j-spring-boot/src/test/java/org/apache/logging/log4j/spring/boot/Log4j2CloudConfigLoggingSystemTest.java
index 3731f232c9..a4da7822ff 100644
--- 
a/log4j-spring-boot/src/test/java/org/apache/logging/log4j/spring/boot/Log4j2CloudConfigLoggingSystemTest.java
+++ 
b/log4j-spring-boot/src/test/java/org/apache/logging/log4j/spring/boot/Log4j2CloudConfigLoggingSystemTest.java
@@ -37,7 +37,7 @@ public class Log4j2CloudConfigLoggingSystemTest {
         LoggerContext lc = LogManager.getContext(); // Initialize LogManager 
to here to prevent a failure trying to
                                                     // initialize it from 
StatusLogger.
         System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, 
customLog4j2Location);
-        Log4j2CloudConfigLoggingSystem cloudLoggingSystem = new 
Log4j2CloudConfigLoggingSystem(
+        Log4j2SpringBootLoggingSystem cloudLoggingSystem = new 
Log4j2SpringBootLoggingSystem(
                 this.getClass().getClassLoader());
         List<String> standardConfigLocations = 
Arrays.asList(cloudLoggingSystem.getStandardConfigLocations());
         assertTrue(standardConfigLocations.contains(customLog4j2Location));
@@ -45,7 +45,7 @@ public class Log4j2CloudConfigLoggingSystemTest {
     }
 
     @Test
-    @SetSystemProperty(key = 
Log4j2CloudConfigLoggingSystem.LOG4J2_DISABLE_CLOUD_CONFIG_LOGGING_SYSTEM, 
value = "true")
+    @SetSystemProperty(key = 
Log4j2SpringBootLoggingSystem.LOG4J2_DISABLE_CLOUD_CONFIG_LOGGING_SYSTEM, value 
= "true")
     public void testUseLog4j2LoggingSystem() {
         LoggingSystem loggingSystem = 
LoggingSystem.get(getClass().getClassLoader());
         assertTrue(loggingSystem.getClass().equals(Log4J2LoggingSystem.class));
@@ -54,6 +54,6 @@ public class Log4j2CloudConfigLoggingSystemTest {
     @Test
     public void testLoggingSystemEnabled() {
         LoggingSystem loggingSystem = 
LoggingSystem.get(getClass().getClassLoader());
-        
assertTrue(loggingSystem.getClass().equals(Log4j2CloudConfigLoggingSystem.class));
+        
assertTrue(loggingSystem.getClass().equals(Log4j2SpringBootLoggingSystem.class));
     }
 }
diff --git 
a/log4j-spring-boot/src/test/java/org/apache/logging/log4j/spring/boot/SpringLookupTest.java
 
b/log4j-spring-boot/src/test/java/org/apache/logging/log4j/spring/boot/SpringLookupTest.java
index eb264f8e99..a10e6d9f0e 100644
--- 
a/log4j-spring-boot/src/test/java/org/apache/logging/log4j/spring/boot/SpringLookupTest.java
+++ 
b/log4j-spring-boot/src/test/java/org/apache/logging/log4j/spring/boot/SpringLookupTest.java
@@ -39,7 +39,7 @@ public class SpringLookupTest {
         env.setDefaultProfiles("one", "two");
         env.setProperty("app.property", "test");
         LoggerContext context = (LoggerContext) LogManager.getContext(false);
-        context.putObject(Log4j2CloudConfigLoggingSystem.ENVIRONMENT_KEY, env);
+        context.putObject(Log4j2SpringBootLoggingSystem.ENVIRONMENT_KEY, env);
         SpringLookup lookup = new SpringLookup();
         String result = lookup.lookup("profiles.active");
         assertNotNull("No active profiles", result);
@@ -66,7 +66,7 @@ public class SpringLookupTest {
         env.setActiveProfiles("test");
         env.setProperty("app.property", "test");
         LoggerContext context = (LoggerContext) LogManager.getContext(false);
-        context.putObject(Log4j2CloudConfigLoggingSystem.ENVIRONMENT_KEY, env);
+        context.putObject(Log4j2SpringBootLoggingSystem.ENVIRONMENT_KEY, env);
 
         StrLookup lookup = new Interpolator();
         String result = lookup.lookup("spring:profiles.active");
diff --git 
a/log4j-spring-boot/src/test/java/org/apache/logging/log4j/spring/boot/SpringProfileTest.java
 
b/log4j-spring-boot/src/test/java/org/apache/logging/log4j/spring/boot/SpringProfileTest.java
index e7a90df08b..0d7432aefe 100644
--- 
a/log4j-spring-boot/src/test/java/org/apache/logging/log4j/spring/boot/SpringProfileTest.java
+++ 
b/log4j-spring-boot/src/test/java/org/apache/logging/log4j/spring/boot/SpringProfileTest.java
@@ -43,7 +43,7 @@ public class SpringProfileTest {
     public static void before() {
         loggerContext = (LoggerContext) LogManager.getContext(false);
         env = new MockEnvironment();
-        
loggerContext.putObject(Log4j2CloudConfigLoggingSystem.ENVIRONMENT_KEY, env);
+        loggerContext.putObject(Log4j2SpringBootLoggingSystem.ENVIRONMENT_KEY, 
env);
     }
 
 
diff --git a/log4j-spring-cloud-config/log4j-spring-cloud-config-client/pom.xml 
b/log4j-spring-cloud-config/log4j-spring-cloud-config-client/pom.xml
index 2eb9582c4a..f1410cf5a0 100644
--- a/log4j-spring-cloud-config/log4j-spring-cloud-config-client/pom.xml
+++ b/log4j-spring-cloud-config/log4j-spring-cloud-config-client/pom.xml
@@ -93,6 +93,11 @@
       <artifactId>log4j-core-test</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-spring-boot</artifactId>
+      <version>${project.version}</version>
+    </dependency>
     <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-test</artifactId>
diff --git 
a/log4j-spring-cloud-config/log4j-spring-cloud-config-samples/log4j-spring-cloud-config-sample-application/pom.xml
 
b/log4j-spring-cloud-config/log4j-spring-cloud-config-samples/log4j-spring-cloud-config-sample-application/pom.xml
index 0c9caaf96a..fa72ea83c7 100644
--- 
a/log4j-spring-cloud-config/log4j-spring-cloud-config-samples/log4j-spring-cloud-config-sample-application/pom.xml
+++ 
b/log4j-spring-cloud-config/log4j-spring-cloud-config-samples/log4j-spring-cloud-config-sample-application/pom.xml
@@ -42,6 +42,13 @@
       <artifactId>log4j-jcl</artifactId>
       <version>${project.version}</version>
     </dependency>
+
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-spring-boot</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+
     <!-- Spring Boot dependencies -->
     <dependency>
       <groupId>org.springframework.boot</groupId>
diff --git a/pom.xml b/pom.xml
index e272ec612a..56af379def 100644
--- a/pom.xml
+++ b/pom.xml
@@ -225,8 +225,8 @@
     <logbackVersion>1.2.3</logbackVersion>
     <jackson1Version>1.9.13</jackson1Version>
     <jackson2Version>2.12.4</jackson2Version>
-    <spring-boot.version>2.5.7</spring-boot.version>
-    <springVersion>5.3.13</springVersion>
+    <spring-boot.version>2.6.7</spring-boot.version>
+    <springVersion>5.3.19</springVersion>
     <kubernetes-client.version>4.6.1</kubernetes-client.version>
     <flumeVersion>1.9.0</flumeVersion>
     <disruptorVersion>3.4.4</disruptorVersion>
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f68128457a..ae81982393 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -199,7 +199,9 @@
       </action>
     </release>
     <release version="2.18.0" date="20YY-MM-DD" description="GA Release 
2.17.3">
-      <!-- FIXES -->
+      <action issue="LOG4J2-3506" dev="rgoers" type="update">
+        Support Spring 2.6.x.
+      </action>
       <action issue="LOG4J2-3493" dev="rgoers" type="fix" due-to="Dmytro 
Voloshyn">
         ClassArbiter's newBuilder method referenced the wrong class.
       </action>
@@ -236,7 +238,6 @@
       <action issue="LOG4J2-3475" dev="jjlin" type="fix" due-to="Jeremy Lin">
         Add missing message parameterization in RegexFilter.
       </action>
-      <!-- Additions -->
       <action issue="LOG4J2-3495" dev="rgoers" type="fix">
         Add MutableThreadContextMapFilter.
       </action>

Reply via email to