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:51 UTC

[logging-log4j2] branch master updated (f590109 -> 73bbce3)

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

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


    from f590109  Use some symmetry in naming: We already have 'configurationStrSubstitutor', so rename 'subst' to 'runtimeStrSubstitutor'.
     new 57e574d  Add and @Ignore test.
     new 73bbce3  Log4j 1 configuration processing should use Log4j 1 variable interpolation instead of the Log4j 2 implementation.

The 2 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:
 .../org/apache/log4j/builders/AbstractBuilder.java |  8 ++------
 .../log4j/config/PropertiesConfigurationTest.java  |  2 +-
 ...Test.java => XmlRollingWithPropertiesTest.java} | 14 +++++++------
 ...faultInit.xml => log4j1-rolling-properties.xml} | 24 ++++++++++------------
 4 files changed, 22 insertions(+), 26 deletions(-)
 copy log4j-1.2-api/src/test/java/org/apache/log4j/config/{PropertiesRollingWithPropertiesTest.java => XmlRollingWithPropertiesTest.java} (81%)
 copy log4j-1.2-api/src/test/resources/{log4j1-1.2.17/input/xml/defaultInit.xml => log4j1-rolling-properties.xml} (67%)

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

Posted by gg...@apache.org.
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;

[logging-log4j2] 01/02: Add and @Ignore test.

Posted by gg...@apache.org.
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 57e574df2e6a5d91545b5439362619bbca3b4508
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jan 16 10:29:02 2022 -0500

    Add and @Ignore test.
    
    Simpler to add @Ignore'd test than to swap git stashes back and forth.
---
 .../log4j/config/XmlRollingWithPropertiesTest.java | 59 ++++++++++++++++++++++
 .../test/resources/log4j1-rolling-properties.xml   | 31 ++++++++++++
 2 files changed, 90 insertions(+)

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
new file mode 100644
index 0000000..858ba68
--- /dev/null
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/XmlRollingWithPropertiesTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.log4j.config;
+
+import static org.junit.Assert.assertTrue;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.apache.logging.log4j.test.SystemPropertyTestRule;
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TestRule;
+
+/**
+ * Test configuration from Properties.
+ */
+@Ignore
+public class XmlRollingWithPropertiesTest {
+
+    private static final String TEST_DIR = "target/" + XmlRollingWithPropertiesTest.class.getSimpleName();
+
+    @ClassRule
+    public static TestRule SP_RULE = RuleChain.emptyRuleChain()
+    //@formatter:off
+        .around(SystemPropertyTestRule.create("test.directory", TEST_DIR))
+        .around(SystemPropertyTestRule.create("log4j.configuration", "target/test-classes/log4j1-rolling-properties.xml"));
+    //@formatter:on
+
+    @Test
+    public void testProperties() throws Exception {
+        // ${test.directory}/logs/etl.log
+        Logger logger = LogManager.getLogger("test");
+        logger.debug("This is a test of the root logger");
+        Path path = Paths.get(TEST_DIR, "logs/etl.log");
+        assertTrue("Log file was not created", Files.exists(path));
+        assertTrue("Log file is empty", Files.size(path) > 0);
+    }
+
+}
diff --git a/log4j-1.2-api/src/test/resources/log4j1-rolling-properties.xml b/log4j-1.2-api/src/test/resources/log4j1-rolling-properties.xml
new file mode 100644
index 0000000..c138a25
--- /dev/null
+++ b/log4j-1.2-api/src/test/resources/log4j1-rolling-properties.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+  
+       http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<!-- See https://issues.apache.org/jira/browse/LOG4J2-3328 -->
+<log4j:configuration>
+  <appender name="DAILY" class="org.apache.log4j.RollingFileAppender">
+    <param name="File" value="${sys:test.directory}/logs/etl.log" />
+    <param name="DatePattern" value="'.'yyyy-MM-dd" />
+    <layout class="org.apache.log4j.PatternLayout">
+      <param name="ConversionPattern" value="GATEWAY: %p %d [%t] %c{1}.%M(%L) | %m%n" />
+    </layout>
+  </appender>
+  <root>
+    <priority value="OFF" />
+    <appender-ref ref="DAILY" />
+  </root>
+</log4j:configuration>