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

pkarwasz pushed a commit to branch fix/3770_LoggerContext_start
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 3818828ca1795aa86b938c4690bc774e86b65d17
Author: Piotr P. Karwasz <[email protected]>
AuthorDate: Sat Jun 21 12:22:08 2025 +0200

    fix: Restore Backward Compatibility with Spring Boot Reconfiguration
    
    Although Spring Boot never directly starts a `LoggerContext`, its logging 
system — including our `Log4j2SpringBootLoggingSystem` and equivalents in 
Spring Boot 2.x and 3.x — has consistently used 
`LoggerContext.start(Configuration)` for reconfiguration.
    
    To maintain backward compatibility with these usages, 
`start(Configuration)` now falls back to `reconfigure(Configuration)` if the 
context is already started.
    
    Closes #3770
---
 .../java/org/apache/logging/log4j/core/LoggerContext.java | 15 ++++++++++++---
 src/changelog/.2.x.x/3770_LoggerContext_start.xml         | 12 ++++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
index bf2f77383c..15922bde01 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
@@ -313,20 +313,29 @@ public class LoggerContext extends AbstractLifeCycle
 
     /**
      * Starts with a specific configuration.
-     *
+     * <p>
+     *     <strong>Warning:</strong> for backward compatibility with existent 
usages, most notably Spring Boot,
+     *     this method falls back to {@link #reconfigure(Configuration)} if 
the context is already started.
+     *     Relying on this behavior is not recommended for new usages, as it 
may change in the future major versions.
+     * </p>
      * @param config The new Configuration.
      */
     public void start(final Configuration config) {
         LOGGER.info("Starting {}[name={}] with configuration {}...", 
getClass().getSimpleName(), getName(), config);
         if (configLock.tryLock()) {
             try {
-                if (this.isInitialized() || this.isStopped()) {
+                if (isInitialized() || isStopped()) {
                     setStarting();
                     reconfigure(config);
                     if (this.configuration.isShutdownHookEnabled()) {
                         setUpShutdownHook();
                     }
-                    this.setStarted();
+                    setStarted();
+                } else {
+                    // Required for Spring Boot integration:
+                    // Both `Log4jSpringBootLoggingSystem` and its Spring Boot 
3.x equivalent
+                    // invoke `start()` even during context reconfiguration.
+                    reconfigure(config);
                 }
             } finally {
                 configLock.unlock();
diff --git a/src/changelog/.2.x.x/3770_LoggerContext_start.xml 
b/src/changelog/.2.x.x/3770_LoggerContext_start.xml
new file mode 100644
index 0000000000..84416d9c54
--- /dev/null
+++ b/src/changelog/.2.x.x/3770_LoggerContext_start.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns="https://logging.apache.org/xml/ns";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="
+           https://logging.apache.org/xml/ns
+           https://logging.apache.org/xml/ns/log4j-changelog-0.xsd";
+       type="fixed">
+  <issue id="3770" 
link="https://github.com/apache/logging-log4j2/issues/3770"/>
+  <description format="asciidoc">
+    Restore backward compatibility with the Spring Boot reconfiguration 
process.
+  </description>
+</entry>

Reply via email to