You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2022/01/16 15:45:53 UTC

[logging-log4j2] 02/02: Log4j 1 configuration processing should use Log4j 1 variable interpolation instead of the Log4j 2 implementation.

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

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

commit 73bbce320175c4024137518f21c1e85a65a7524e
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jan 16 10:39:01 2022 -0500

    Log4j 1 configuration processing should use Log4j 1 variable
    interpolation instead of the Log4j 2 implementation.
---
 .../src/main/java/org/apache/log4j/builders/AbstractBuilder.java  | 8 ++------
 .../java/org/apache/log4j/config/PropertiesConfigurationTest.java | 2 +-
 .../org/apache/log4j/config/XmlRollingWithPropertiesTest.java     | 2 +-
 3 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/AbstractBuilder.java b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/AbstractBuilder.java
index 77a193e..533b34c 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/AbstractBuilder.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/AbstractBuilder.java
@@ -31,8 +31,6 @@ import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.filter.CompositeFilter;
 import org.apache.logging.log4j.core.filter.ThresholdFilter;
-import org.apache.logging.log4j.core.lookup.ConfigurationStrSubstitutor;
-import org.apache.logging.log4j.core.lookup.StrSubstitutor;
 import org.apache.logging.log4j.status.StatusLogger;
 
 /**
@@ -51,11 +49,9 @@ public abstract class AbstractBuilder {
 
     private final String prefix;
     private final Properties properties;
-    private final StrSubstitutor strSubstitutor;
 
     public AbstractBuilder() {
         this.prefix = null;
-        this.strSubstitutor = new ConfigurationStrSubstitutor(System.getProperties());
         this.properties = new Properties();
     }
 
@@ -68,7 +64,6 @@ public abstract class AbstractBuilder {
         // normalize keys to lower case for case-insensitive access.
         props.forEach((k, v) -> map.put(toLowerCase(k.toString()), v.toString()));
         props.entrySet().forEach(e -> this.properties.put(toLowerCase(e.getKey().toString()), e.getValue()));
-        this.strSubstitutor = new ConfigurationStrSubstitutor(map);
     }
 
     public String getProperty(String key) {
@@ -79,7 +74,8 @@ public abstract class AbstractBuilder {
         String fullKey = prefix + key;
         String value = properties.getProperty(fullKey);
         value = value != null ? value : properties.getProperty(toLowerCase(fullKey), defaultValue);
-        return strSubstitutor.replace(value);
+        value = value == null ? defaultValue : OptionConverter.substVars(value, properties);
+        return value == null ? defaultValue : value;
     }
 
     public boolean getBooleanProperty(String key) {
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesConfigurationTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesConfigurationTest.java
index 48bf528..bc1fb51 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesConfigurationTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesConfigurationTest.java
@@ -156,7 +156,7 @@ public class PropertiesConfigurationTest {
             final String name = "FILE_APPENDER";
             final Appender appender = configuration.getAppender(name);
             assertNotNull(name, appender);
-            assertTrue(appender instanceof FileAppender);
+            assertTrue(appender.getClass().getName(), appender instanceof FileAppender);
             final FileAppender fileAppender = (FileAppender) appender;
             // Two slashes because that's how the config file is setup.
             assertEquals(testPathLocation + "/hadoop.log", fileAppender.getFileName());
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/XmlRollingWithPropertiesTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/XmlRollingWithPropertiesTest.java
index 858ba68..a56c0af 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/XmlRollingWithPropertiesTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/XmlRollingWithPropertiesTest.java
@@ -24,7 +24,7 @@ import java.nio.file.Paths;
 
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
-import org.apache.logging.log4j.test.SystemPropertyTestRule;
+import org.apache.logging.log4j.core.test.SystemPropertyTestRule;
 import org.junit.ClassRule;
 import org.junit.Ignore;
 import org.junit.Test;