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/10 13:25:31 UTC

[logging-log4j2] branch master updated (1f74096 -> 01e38b5)

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 1f74096  Merge branch 'master' of https://gitbox.apache.org/repos/asf/logging-log4j2.git
     new a554dbc  [LOG4J2-3326] Fix parsing filters from Log4j 1.2 properties configuration file (#680)
     new 6996b9e  [LOG4J2-3326] Fix parsing filters from Log4j 1.2 properties configuration file #680.
     new 01e38b5  [LOG4J2-3326] Log4j 1.2 bridge fixes parsing filters in properties configuration file #680.

The 3 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:
 .../log4j/config/PropertiesConfiguration.java      |  2 +-
 .../log4j/config/PropertiesConfigurationTest.java  | 23 ++++++++++++
 .../src/test/resources/LOG4J2-3326.properties      | 43 +++++++++++-----------
 src/changes/changes.xml                            |  6 +++
 4 files changed, 52 insertions(+), 22 deletions(-)
 copy log4j-spring-cloud-config/log4j-spring-cloud-config-samples/log4j-spring-cloud-config-sample-application/docker/logs.sh => log4j-1.2-api/src/test/resources/LOG4J2-3326.properties (72%)
 mode change 100755 => 100644

[logging-log4j2] 01/03: [LOG4J2-3326] Fix parsing filters from Log4j 1.2 properties configuration file (#680)

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 a554dbc979eea0949e8dcee72eed3edfac5f7518
Author: benjaminr-ps <be...@pure-systems.com>
AuthorDate: Mon Jan 10 14:17:51 2022 +0100

    [LOG4J2-3326] Fix parsing filters from Log4j 1.2 properties configuration file (#680)
    
    * Use specific filter key as prefix while parsing configuration
    
    Problem: The log4j 1.x configuration file is not properly parsed, in regards of filters. Whatever is configured in file, is getting ignored, and default values are used.
    E.g. for "level range filter" the LevelMax is not properly found (eventhough properly read as property).
    
    Root cause: The default filter prefix is used, instead of specific filter key.
    
    * add test, verifying LevelRangeFilter properly parsed/configured
    
    ...with values of properties configuration file
---
 .../log4j/config/PropertiesConfiguration.java      |  2 +-
 .../log4j/config/PropertiesConfigurationTest.java  | 23 ++++++++++++++++++++++
 .../src/test/resources/LOG4J2-3326.properties      | 22 +++++++++++++++++++++
 3 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/config/PropertiesConfiguration.java b/log4j-1.2-api/src/main/java/org/apache/log4j/config/PropertiesConfiguration.java
index 7a1fee4..1e4de2d 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/config/PropertiesConfiguration.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/config/PropertiesConfiguration.java
@@ -564,7 +564,7 @@ public class PropertiesConfiguration  extends Log4j1Configuration {
             String clazz = props.getProperty(entry.getKey());
             Filter filter = null;
             if (clazz != null) {
-                filter = manager.parseFilter(clazz, filterPrefix, props, this);
+                filter = manager.parseFilter(clazz, entry.getKey(), props, this);
                 if (filter == null) {
                     LOGGER.debug("Filter key: [{}] class: [{}] props: {}", entry.getKey(), clazz, entry.getValue());
                     filter = buildFilter(clazz, appenderName, entry.getValue());
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 b197367..63f8e32 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
@@ -30,12 +30,17 @@ import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
 import org.apache.log4j.bridge.AppenderAdapter;
 import org.apache.log4j.bridge.FilterAdapter;
+import org.apache.log4j.bridge.FilterWrapper;
 import org.apache.log4j.spi.LoggingEvent;
+import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.appender.FileAppender;
 import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.plugins.util.PluginManager;
+import org.apache.logging.log4j.core.filter.CompositeFilter;
 import org.apache.logging.log4j.core.filter.Filterable;
+import org.apache.logging.log4j.core.filter.LevelRangeFilter;
 import org.junit.Test;
 
 /**
@@ -85,6 +90,24 @@ public class PropertiesConfigurationTest {
             assertTrue(filter.getFilter() instanceof NeutralFilterFixture);
         }
     }
+    
+    @Test
+    public void testConsoleAppenderLevelRangeFilter() throws Exception {
+        PluginManager.addPackage("org.apache.log4j.builders.filter");
+        try (LoggerContext loggerContext = TestConfigurator.configure("target/test-classes/LOG4J2-3326.properties")) {
+            final Configuration configuration = loggerContext.getConfiguration();
+            assertNotNull(configuration);
+            final Appender appender = configuration.getAppender("CUSTOM");
+            assertNotNull(appender);
+            final Filterable filterable = (Filterable) appender;
+            final CompositeFilter filter = (CompositeFilter) filterable.getFilter();
+            final org.apache.logging.log4j.core.Filter[] filters = filter.getFiltersArray();
+            final LevelRangeFilter customFilterReal = (LevelRangeFilter) ((FilterWrapper) ((FilterAdapter) filters[0]).getFilter()).getFilter();
+            assertEquals(Level.ALL, customFilterReal.getMinLevel());
+            final LevelRangeFilter defaultFilter = (LevelRangeFilter) ((FilterWrapper) ((FilterAdapter) filters[1]).getFilter()).getFilter();
+            assertEquals(Level.TRACE, defaultFilter.getMinLevel());
+      }
+    }
 
     @Test
     public void testListAppender() throws Exception {
diff --git a/log4j-1.2-api/src/test/resources/LOG4J2-3326.properties b/log4j-1.2-api/src/test/resources/LOG4J2-3326.properties
new file mode 100644
index 0000000..8725a14
--- /dev/null
+++ b/log4j-1.2-api/src/test/resources/LOG4J2-3326.properties
@@ -0,0 +1,22 @@
+# 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.
+
+
+log4j.appender.CUSTOM=org.apache.log4j.CustomNoopAppender
+log4j.appender.CUSTOM.filter.1=org.apache.log4j.varia.LevelRangeFilter
+log4j.appender.CUSTOM.filter.1.levelMin=ALL
+log4j.appender.CUSTOM.filter.2=org.apache.log4j.varia.LevelRangeFilter
+
+log4j.rootLogger=trace, CUSTOM
\ No newline at end of file

[logging-log4j2] 03/03: [LOG4J2-3326] Log4j 1.2 bridge fixes parsing filters in properties configuration file #680.

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 01e38b528d9ec5d64f15c4ba5ae2a94105998a82
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jan 10 08:25:28 2022 -0500

    [LOG4J2-3326] Log4j 1.2 bridge fixes parsing filters in properties
    configuration file #680.
---
 src/changes/changes.xml | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 809b070..95c4e9d 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -254,6 +254,12 @@
       <action dev="ggregory" type="fix">
         Log4j 1.2 bridge adds org.apache.log4j.spi.DefaultRepositorySelector.
       </action>
+      <action dev="ggregory" type="fix">
+        Log4j 1.2 bridge implements LogManager.getCurrentLoggers() fully.
+      </action>
+      <action dev="ggregory" type="fix" issue="LOG4J2-3326" due-to="Benjamin Röhl, Gary Gregory">
+        Log4j 1.2 bridge fixes parsing filters in properties configuration file #680.
+      </action>
       <!-- ADD -->
       <action issue="LOG4J2-3282" dev="ckozak" type="add" due-to="Michael Vorburger">
         Add the log4j-to-jul JDK Logging Bridge

[logging-log4j2] 02/03: [LOG4J2-3326] Fix parsing filters from Log4j 1.2 properties configuration file #680.

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 6996b9e784809684b3b8cfaad8378c4ccee65a62
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jan 10 08:21:02 2022 -0500

    [LOG4J2-3326] Fix parsing filters from Log4j 1.2 properties
    configuration file #680.
---
 log4j-1.2-api/src/test/resources/LOG4J2-3326.properties | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/log4j-1.2-api/src/test/resources/LOG4J2-3326.properties b/log4j-1.2-api/src/test/resources/LOG4J2-3326.properties
index 8725a14..f0da9a5 100644
--- a/log4j-1.2-api/src/test/resources/LOG4J2-3326.properties
+++ b/log4j-1.2-api/src/test/resources/LOG4J2-3326.properties
@@ -19,4 +19,4 @@ log4j.appender.CUSTOM.filter.1=org.apache.log4j.varia.LevelRangeFilter
 log4j.appender.CUSTOM.filter.1.levelMin=ALL
 log4j.appender.CUSTOM.filter.2=org.apache.log4j.varia.LevelRangeFilter
 
-log4j.rootLogger=trace, CUSTOM
\ No newline at end of file
+log4j.rootLogger=trace, CUSTOM