You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by pk...@apache.org on 2025/06/21 10:39:59 UTC

(logging-log4j2) branch fix/3770_LoggerContext_start updated (3818828ca1 -> 68952602fc)

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

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


 discard 3818828ca1 fix: Restore Backward Compatibility with Spring Boot Reconfiguration
     new 68952602fc fix: Restore Backward Compatibility with Spring Boot Reconfiguration

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (3818828ca1)
            \
             N -- N -- N   refs/heads/fix/3770_LoggerContext_start (68952602fc)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/logging/log4j/core/LoggerContext.java    | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)


(logging-log4j2) 01/01: fix: Restore Backward Compatibility with Spring Boot Reconfiguration

Posted by pk...@apache.org.
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 68952602fc92f5dc1bee9093a5b740cfa50ba1d5
Author: Piotr P. Karwasz <pk...@apache.org>
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
---
 .../apache/logging/log4j/core/LoggerContext.java   | 30 ++++++++++++++++++----
 src/changelog/.2.x.x/3770_LoggerContext_start.xml  | 12 +++++++++
 2 files changed, 37 insertions(+), 5 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..6db471cb87 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
@@ -286,6 +286,16 @@ public class LoggerContext extends AbstractLifeCycle
         return (LoggerContext) LogManager.getContext(loader, currentContext, configLocation);
     }
 
+    /**
+     * Starts the context using the configuration specified by {@link #getConfigLocation()}.
+     * <p>
+     *   If the configuration location is {@code null}, Log4j will search for a configuration file
+     *   using the default classpath resources. For details on the search order and supported formats,
+     *   see the
+     *   <a href="https://logging.apache.org/log4j/2.x/manual/configuration.html#automatic-configuration">
+     *   Log4j 2 Configuration File Location documentation</a>.
+     * </p>
+     */
     @Override
     public void start() {
         LOGGER.debug("Starting LoggerContext[name={}, {}]...", getName(), this);
@@ -312,21 +322,31 @@ public class LoggerContext extends AbstractLifeCycle
     }
 
     /**
-     * Starts with a specific configuration.
-     *
-     * @param config The new Configuration.
+     * Starts the context using a specific configuration.
+     * <p>
+     *   <strong>Warning:</strong> For backward compatibility, especially with Spring Boot,
+     *   if the context is already started, this method will fall back to {@link #reconfigure(Configuration)}.
+     *   This behavior is maintained for legacy integrations and may change in future major versions.
+     *   New code should not rely on this fallback.
+     * </p>
+     * @param config The new {@link Configuration} to use for this context
      */
     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>