Repository: logging-log4j2
Updated Branches:
  refs/heads/master 518ff5645 -> 71cab8985


[LOG4J2-1523] Log4j 1 appenders. Classic RollingFileAppender with
property substitutions.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/71cab898
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/71cab898
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/71cab898

Branch: refs/heads/master
Commit: 71cab89858ef319b35014dbe59de3e254e8cf205
Parents: 518ff56
Author: Gary Gregory <ggreg...@apache.org>
Authored: Wed Sep 21 21:05:38 2016 -0700
Committer: Gary Gregory <ggreg...@apache.org>
Committed: Wed Sep 21 21:05:38 2016 -0700

----------------------------------------------------------------------
 .../log4j/config/Log4j1ConfigurationParser.java  |  9 ++++++---
 .../config/Log4j1ConfigurationFactoryTest.java   |  1 -
 .../log4j/core/lookup/StrSubstitutor.java        | 19 +++++++++++++++++++
 3 files changed, 25 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/71cab898/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java
----------------------------------------------------------------------
diff --git 
a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java
 
b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java
index f529049..579e600 100644
--- 
a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java
+++ 
b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java
@@ -33,6 +33,7 @@ import 
org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFact
 import org.apache.logging.log4j.core.config.builder.api.LayoutComponentBuilder;
 import 
org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder;
 import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
+import org.apache.logging.log4j.core.lookup.StrSubstitutor;
 import org.apache.logging.log4j.status.StatusLogger;
 
 /**
@@ -43,6 +44,8 @@ import org.apache.logging.log4j.status.StatusLogger;
 public class Log4j1ConfigurationParser {
 
        private final Properties properties = new Properties();
+       private StrSubstitutor strSubstitutor;
+       
        private final ConfigurationBuilder<BuiltConfiguration> builder = 
ConfigurationBuilderFactory
                        .newConfigurationBuilder();
 
@@ -61,6 +64,7 @@ public class Log4j1ConfigurationParser {
        public ConfigurationBuilder<BuiltConfiguration> 
buildConfigurationBuilder(final InputStream input)
                        throws IOException {
                properties.load(input);
+               strSubstitutor = new StrSubstitutor(properties);
                final String rootCategoryValue = getLog4jValue("rootCategory");
                final String rootLoggerValue = getLog4jValue("rootLogger");
                if (rootCategoryValue == null && rootLoggerValue == null) {
@@ -324,7 +328,6 @@ public class Log4j1ConfigurationParser {
                                }
                        }
                }
-
        }
 
        private String getLog4jAppenderValue(final String appenderName, final 
String attributeName) {
@@ -332,11 +335,11 @@ public class Log4j1ConfigurationParser {
        }
 
        private String getProperty(final String key) {
-               return properties.getProperty(key);
+               return strSubstitutor.replace(properties.getProperty(key));
        }
 
        private String getProperty(final String key, String defaultValue) {
-               return properties.getProperty(key, defaultValue);
+               return strSubstitutor.replace(properties.getProperty(key, 
defaultValue));
        }
 
        private String getLog4jAppenderValue(final String appenderName, final 
String attributeName,

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/71cab898/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
 
b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
index d5ee84f..8c6260d 100644
--- 
a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
+++ 
b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
@@ -140,7 +140,6 @@ public class Log4j1ConfigurationFactoryTest {
        }
 
        @Test
-       @Ignore("TODO")
        public void testRollingFileAppenderWithProperties() throws Exception {
                
testRollingFileAppender("config-1.2/log4j-RollingFileAppender-with-props.properties");
        }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/71cab898/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/StrSubstitutor.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/StrSubstitutor.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/StrSubstitutor.java
index 26e09cb..b7ef7e6 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/StrSubstitutor.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/StrSubstitutor.java
@@ -199,6 +199,7 @@ public class StrSubstitutor implements ConfigurationAware {
     public StrSubstitutor() {
         this(null, DEFAULT_PREFIX, DEFAULT_SUFFIX, DEFAULT_ESCAPE);
     }
+    
     /**
      * Creates a new instance and initializes it. Uses defaults for variable
      * prefix and suffix and the escaping character.
@@ -251,6 +252,16 @@ public class StrSubstitutor implements ConfigurationAware {
     }
 
     /**
+     * Creates a new instance and initializes it. Uses defaults for variable
+     * prefix and suffix and the escaping character.
+     *
+     * @param properties  the map with the variables' values, may be null
+     */
+    public StrSubstitutor(Properties properties) {
+        this(toTypeSafeMap(properties));
+    }
+    
+    /**
      * Creates a new instance and initializes it.
      *
      * @param variableResolver  the variable resolver, may be null
@@ -380,6 +391,14 @@ public class StrSubstitutor implements ConfigurationAware {
         return StrSubstitutor.replace(source, valueMap);
     }
 
+    private static Map<String, String> toTypeSafeMap(Properties properties) {
+        Map<String, String> map = new HashMap<>(properties.size());
+        for (final String name : properties.stringPropertyNames()) {
+            map.put(name, properties.getProperty(name));
+        }
+        return map;
+    }
+
     //-----------------------------------------------------------------------
     /**
      * Replaces all the occurrences of variables with their matching values

Reply via email to