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

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


The following commit(s) were added to refs/heads/2.x by this push:
     new 516e85bdbe Fix properties configuration support for per-logger 
properties (#4142)
516e85bdbe is described below

commit 516e85bdbe32228b8db4fd300ada0efe15fe6ada
Author: Ramanathan <[email protected]>
AuthorDate: Fri Jul 24 16:20:24 2026 +0530

    Fix properties configuration support for per-logger properties (#4142)
    
    Co-authored-by: Volkan Yazıcı <[email protected]>
---
 .../config/properties/PropertiesConfigurationTest.java   | 16 ++++++++++++++++
 .../src/test/resources/log4j2-properties.properties      |  8 ++++++++
 .../properties/PropertiesConfigurationBuilder.java       |  7 +++++--
 ...rties_configuration_support_for_logger_properties.xml | 13 +++++++++++++
 4 files changed, 42 insertions(+), 2 deletions(-)

diff --git 
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTest.java
 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTest.java
index 181879489c..e2b76e7072 100644
--- 
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTest.java
+++ 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTest.java
@@ -34,6 +34,7 @@ import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.LoggerConfig;
+import org.apache.logging.log4j.core.config.Property;
 import org.apache.logging.log4j.core.filter.ThresholdFilter;
 import org.apache.logging.log4j.core.test.appender.ListAppender;
 import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
@@ -56,6 +57,21 @@ class PropertiesConfigurationTest {
         final Filter filter = config.getFilter();
         assertNotNull(filter, "No Filter");
         assertInstanceOf(ThresholdFilter.class, filter, "Not a Threshold 
Filter");
+
+        final List<Property> rootProperties = 
config.getRootLogger().getPropertyList();
+        assertNotNull(rootProperties, "Root properties list should not be 
null");
+        assertEquals(1, rootProperties.size());
+        assertEquals("client.address", rootProperties.get(0).getName());
+        assertEquals("${web:request.remoteAddress}", 
rootProperties.get(0).getValue());
+
+        final LoggerConfig log4jLogger = 
loggers.get("org.apache.logging.log4j");
+        assertNotNull(log4jLogger, "org.apache.logging.log4j logger should not 
be null");
+        final List<Property> log4jProperties = log4jLogger.getPropertyList();
+        assertNotNull(log4jProperties, "org.apache.logging.log4j properties 
list should not be null");
+        assertEquals(1, log4jProperties.size());
+        assertEquals("subsystem", log4jProperties.get(0).getName());
+        assertEquals("Database", log4jProperties.get(0).getValue());
+
         final Logger logger = LogManager.getLogger(getClass());
         logger.info("Welcome to Log4j!");
     }
diff --git a/log4j-core-test/src/test/resources/log4j2-properties.properties 
b/log4j-core-test/src/test/resources/log4j2-properties.properties
index b2909d0c6f..f525cfb615 100644
--- a/log4j-core-test/src/test/resources/log4j2-properties.properties
+++ b/log4j-core-test/src/test/resources/log4j2-properties.properties
@@ -38,3 +38,11 @@ logger.log4j.additivity = false
 
 rootLogger.appenderRef.console.ref = StdOut
 rootLogger.level = ERROR
+
+rootLogger.property.type = Property
+rootLogger.property.name = client.address
+rootLogger.property.value = $${web:request.remoteAddress}
+
+logger.log4j.property.type = Property
+logger.log4j.property.name = subsystem
+logger.log4j.property.value = Database
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
index 4903e8bcb5..ba25b6626f 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
@@ -312,8 +312,9 @@ public class PropertiesConfigurationBuilder extends 
ConfigurationBuilderFactory
         }
         if (levelAndRefs != null) {
             loggerBuilder.addAttribute("levelAndRefs", levelAndRefs);
+            properties.remove("");
         }
-        return loggerBuilder;
+        return processRemainingProperties(loggerBuilder, properties);
     }
 
     private RootLoggerComponentBuilder createRootLogger(final Properties 
properties) {
@@ -343,8 +344,10 @@ public class PropertiesConfigurationBuilder extends 
ConfigurationBuilderFactory
         addLoggersToComponent(loggerBuilder, properties);
         if (levelAndRefs != null) {
             loggerBuilder.addAttribute("levelAndRefs", levelAndRefs);
+            properties.remove("");
         }
-        return addFiltersToComponent(loggerBuilder, properties);
+        addFiltersToComponent(loggerBuilder, properties);
+        return processRemainingProperties(loggerBuilder, properties);
     }
 
     private LayoutComponentBuilder createLayout(final String appenderName, 
final Properties properties) {
diff --git 
a/src/changelog/.2.x.x/4024_fix_roperties_configuration_support_for_logger_properties.xml
 
b/src/changelog/.2.x.x/4024_fix_roperties_configuration_support_for_logger_properties.xml
new file mode 100644
index 0000000000..f3bc3609fc
--- /dev/null
+++ 
b/src/changelog/.2.x.x/4024_fix_roperties_configuration_support_for_logger_properties.xml
@@ -0,0 +1,13 @@
+<?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="4024" 
link="https://github.com/apache/logging-log4j2/issues/4024"/>
+    <issue id="4142" 
link="https://github.com/apache/logging-log4j2/pull/4142"/>
+    <description format="asciidoc">
+        Fix properties configuration format to correctly parse and apply 
nested custom properties on loggers and root loggers
+    </description>
+</entry>

Reply via email to