From 7eaa939aab2167379b0b614b4ca9749f0f588663 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Mon, 26 Oct 2026 08:30:15 -0700 Subject: [PATCH 1/5] Add back deprecated constructor that Spring Boot uses --- .../logging/log4j/core/config/LoggerConfig.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java index c1810ac1614..42713600d20 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java @@ -201,6 +201,19 @@ public B asBuilder() { } } + /** + * Constructor that sets the name, level and additive values. + * @deprecated - For comapatibilty with 2.x. + * + * @param name The Logger name. + * @param level The Level. + * @param additive true if the Logger is additive, false otherwise. + */ + @Deprecated + public LoggerConfig(final String name, final Level level, final boolean additive) { + this(name, Collections.emptyList(), null, level, additive, null, null, true); + } + /** * Constructor that sets the name, level and additive values. * From fe1172023225cee7b36eef677db5695080abd6a8 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Mon, 26 Oct 2026 10:09:09 -0700 Subject: [PATCH 2/5] restore configuration so subsequent tests don't fail --- .../logging/log4j/core/LoggerUpdateTest.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java index 972908b2379..c921574e371 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java @@ -24,6 +24,7 @@ import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.List; +import java.util.function.Consumer; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.core.config.Configuration; @@ -67,8 +68,13 @@ public void resetLevel(final LoggerContext context) { @Timeout(3) public void testUpdateLoggersPropertyListeners(final LoggerContext context) throws Exception { final Configuration config = context.getConfiguration(); - context.addConfigurationStartedListener(configuration -> assertSame(config, configuration)); - context.updateLoggers(); + final Consumer listener = configuration -> assertSame(config, configuration); + context.addConfigurationStartedListener(listener); + try { + context.updateLoggers(); + } finally { + context.removeConfigurationStartedListener(listener); + } } @Test @@ -76,12 +82,20 @@ public void testUpdateLoggersPropertyListeners(final LoggerContext context) thro void propertyChangeListenerReceivesOldAndNewConfigurationOnReconfiguration(final LoggerContext context) { // Given a java.beans listener, as registered by Log4j Core 2 consumers such as Micrometer final List events = new ArrayList<>(); - context.addPropertyChangeListener(events::add); + final PropertyChangeListener listener = events::add; + context.addPropertyChangeListener(listener); final Configuration previous = context.getConfiguration(); final Configuration replacement = new DefaultConfiguration(); // When the configuration is replaced - context.setConfiguration(replacement); + try { + context.setConfiguration(replacement); + } finally { + // Restore the shared context for the other tests in this class; `previous` has been stopped, + // so reload the original configuration file instead of reinstating it. + context.removePropertyChangeListener(listener); + context.reconfigure(); + } // Then the listener sees the old and the new configuration assertThat(events).isNotEmpty(); From be0636007efadbde55f8c71bf5d0b42488ca0770 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Tue, 27 Oct 2026 12:42:45 -0700 Subject: [PATCH 3/5] Set Configuration --- .../logging/log4j/core/config/LoggerConfig.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java index 42713600d20..4c09932498f 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java @@ -203,7 +203,7 @@ public B asBuilder() { /** * Constructor that sets the name, level and additive values. - * @deprecated - For comapatibilty with 2.x. + * @deprecated - Use {@link #LoggerConfig(String, Level, boolean, Configuration)} instead. * * @param name The Logger name. * @param level The Level. @@ -211,7 +211,15 @@ public B asBuilder() { */ @Deprecated public LoggerConfig(final String name, final Level level, final boolean additive) { - this(name, Collections.emptyList(), null, level, additive, null, null, true); + this( + name, + Collections.emptyList(), + null, + level, + additive, + null, + ((LoggerContext) LogManager.getContext(LoggerConfig.class.getClassLoader(), false)).getConfiguration(), + true); } /** From 202f8aef51d16a0de9568c996f38b914bf21add3 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Tue, 27 Oct 2026 12:52:31 -0700 Subject: [PATCH 4/5] Add changelog entry --- src/changelog/.3.x.x/4433_logger_config.xml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/changelog/.3.x.x/4433_logger_config.xml diff --git a/src/changelog/.3.x.x/4433_logger_config.xml b/src/changelog/.3.x.x/4433_logger_config.xml new file mode 100644 index 00000000000..011bd40007f --- /dev/null +++ b/src/changelog/.3.x.x/4433_logger_config.xml @@ -0,0 +1,14 @@ + + + + 1. Adds back the LoggerConfig constructor used by Spring Boot. + 2. Fix LoggerUpdaterTest: + * testUpdateLoggersPropertyListeners: it now keeps a reference to its configuration-started listener and removes it in a finally block. + * propertyChangeListenerReceivesOldAndNewConfigurationOnReconfiguration: in a finally block, it now removes its property-change listener and calls context.reconfigure(). + + From cc1a95a11805ff36d5f3acf90b29e9fa02335731 Mon Sep 17 00:00:00 2001 From: Ralph Goers Date: Wed, 28 Oct 2026 07:39:16 -0700 Subject: [PATCH 5/5] Fix review comments --- .../apache/logging/log4j/core/LoggerUpdateTest.java | 12 ++++++++++++ src/changelog/.3.x.x/4433_logger_config.xml | 6 ++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java index c921574e371..11ecf929da0 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java @@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertSame; import java.beans.PropertyChangeEvent; @@ -77,6 +78,17 @@ public void testUpdateLoggersPropertyListeners(final LoggerContext context) thro } } + @Test + public void testDeprecatedConstructor(final LoggerContext context) { + try { + Configuration configuration = context.getConfiguration(); + LoggerConfig loggerConfig = new LoggerConfig("test1", Level.INFO, false); + assertThat(loggerConfig).isNotNull(); + } catch (Exception ex) { + fail("Constructor should not have failed: " + ex.getMessage()); + } + } + @Test @SuppressWarnings("deprecation") void propertyChangeListenerReceivesOldAndNewConfigurationOnReconfiguration(final LoggerContext context) { diff --git a/src/changelog/.3.x.x/4433_logger_config.xml b/src/changelog/.3.x.x/4433_logger_config.xml index 011bd40007f..e1962386b2d 100644 --- a/src/changelog/.3.x.x/4433_logger_config.xml +++ b/src/changelog/.3.x.x/4433_logger_config.xml @@ -5,10 +5,8 @@ https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd" type="fixed"> + - 1. Adds back the LoggerConfig constructor used by Spring Boot. - 2. Fix LoggerUpdaterTest: - * testUpdateLoggersPropertyListeners: it now keeps a reference to its configuration-started listener and removes it in a finally block. - * propertyChangeListenerReceivesOldAndNewConfigurationOnReconfiguration: in a finally block, it now removes its property-change listener and calls context.reconfigure(). + Restore the `LoggerConfig(String, Level, boolean)` constructor.