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 2021/12/31 17:05:19 UTC
[logging-log4j2] branch release-2.x updated: Revert "[LOG4J2-3281] PropertiesConfiguration.buildAppender not adding filters"
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/release-2.x by this push:
new 533ad83 Revert "[LOG4J2-3281] PropertiesConfiguration.buildAppender not adding filters"
533ad83 is described below
commit 533ad83014762af808f17124c3e7dffc628bbb0a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Dec 31 12:01:24 2021 -0500
Revert "[LOG4J2-3281] PropertiesConfiguration.buildAppender not adding filters"
This commit breaks revapi.
This reverts commit a1328b9caaba32652da24bf10803c5f5b59b246c.
---
.../org/apache/log4j/builders/BuilderManager.java | 15 ++++-----
.../log4j/config/PropertiesConfiguration.java | 6 ++--
.../java/org/apache/log4j/CustomNoopAppender.java | 39 ----------------------
.../log4j/config/PropertiesConfigurationTest.java | 17 +---------
.../src/test/resources/LOG4J2-3281.properties | 25 --------------
5 files changed, 11 insertions(+), 91 deletions(-)
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/BuilderManager.java b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/BuilderManager.java
index b08ca44..12b0b3c 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/builders/BuilderManager.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/builders/BuilderManager.java
@@ -36,7 +36,6 @@ import org.w3c.dom.Element;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
-import java.util.Objects;
import java.util.Properties;
/**
@@ -47,7 +46,7 @@ public class BuilderManager {
public static final String CATEGORY = "Log4j Builder";
private static final Logger LOGGER = StatusLogger.getLogger();
private final Map<String, PluginType<?>> plugins;
- private static Class<?>[] constructorParams = new Class[] { String.class, Properties.class };
+ private static Class<?>[] constructorParams = new Class[] { String.class, Properties.class};
public BuilderManager() {
final PluginManager manager = new PluginManager(CATEGORY);
@@ -61,7 +60,7 @@ public class BuilderManager {
try {
AppenderBuilder builder = (AppenderBuilder) LoaderUtil.newInstanceOf(plugin.getPluginClass());
return builder.parseAppender(appenderElement, config);
- } catch (ReflectiveOperationException ex) {
+ } catch (InstantiationException | IllegalAccessException | InvocationTargetException ex) {
LOGGER.warn("Unable to load plugin: {} due to: {}", plugin.getKey(), ex.getMessage());
}
}
@@ -70,8 +69,6 @@ public class BuilderManager {
public Appender parseAppender(String name, String className, String prefix, String layoutPrefix,
String filterPrefix, Properties props, PropertiesConfiguration config) {
- Objects.requireNonNull(plugins, "plugins");
- Objects.requireNonNull(className, "className");
PluginType<?> plugin = plugins.get(className.toLowerCase());
if (plugin != null) {
AppenderBuilder builder = createBuilder(plugin, prefix, props);
@@ -88,7 +85,7 @@ public class BuilderManager {
try {
FilterBuilder builder = (FilterBuilder) LoaderUtil.newInstanceOf(plugin.getPluginClass());
return builder.parseFilter(filterElement, config);
- } catch (ReflectiveOperationException ex) {
+ } catch (InstantiationException | IllegalAccessException | InvocationTargetException ex) {
LOGGER.warn("Unable to load plugin: {} due to: {}", plugin.getKey(), ex.getMessage());
}
}
@@ -112,7 +109,7 @@ public class BuilderManager {
try {
LayoutBuilder builder = (LayoutBuilder) LoaderUtil.newInstanceOf(plugin.getPluginClass());
return builder.parseLayout(layoutElement, config);
- } catch (ReflectiveOperationException ex) {
+ } catch (InstantiationException | IllegalAccessException | InvocationTargetException ex) {
LOGGER.warn("Unable to load plugin: {} due to: {}", plugin.getKey(), ex.getMessage());
}
}
@@ -135,7 +132,7 @@ public class BuilderManager {
try {
RewritePolicyBuilder builder = (RewritePolicyBuilder) LoaderUtil.newInstanceOf(plugin.getPluginClass());
return builder.parseRewritePolicy(rewriteElement, config);
- } catch (ReflectiveOperationException ex) {
+ } catch (InstantiationException | IllegalAccessException | InvocationTargetException ex) {
LOGGER.warn("Unable to load plugin: {} due to: {}", plugin.getKey(), ex.getMessage());
}
}
@@ -164,7 +161,7 @@ public class BuilderManager {
@SuppressWarnings("unchecked")
T builder = (T) LoaderUtil.newInstanceOf(clazz);
return builder;
- } catch (ReflectiveOperationException ex) {
+ } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ex) {
LOGGER.warn("Unable to load plugin: {} due to: {}", plugin.getKey(), ex.getMessage());
return null;
}
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 1ca70d4..8b9b3b9 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
@@ -455,8 +455,10 @@ public class PropertiesConfiguration extends Log4j1Configuration {
appender.setErrorHandler(eh);
}
}
- appender.addFilter(parseAppenderFilters(props, filterPrefix, appenderName));
- String[] keys = new String[] { layoutPrefix };
+ parseAppenderFilters(props, filterPrefix, appenderName);
+ String[] keys = new String[] {
+ layoutPrefix,
+ };
addProperties(appender, keys, props, prefix);
if (appender instanceof AppenderWrapper) {
addAppender(((AppenderWrapper) appender).getAppender());
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/CustomNoopAppender.java b/log4j-1.2-api/src/test/java/org/apache/log4j/CustomNoopAppender.java
deleted file mode 100644
index 49de446..0000000
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/CustomNoopAppender.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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;
-
-import org.apache.log4j.spi.LoggingEvent;
-
-public class CustomNoopAppender extends AppenderSkeleton {
-
- @Override
- public void close() {
- // Noop
- }
-
- @Override
- public boolean requiresLayout() {
- return false;
- }
-
- @Override
- protected void append(LoggingEvent event) {
- // Noop
- }
-
-}
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 59757cf..64ee9e3 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
@@ -52,7 +52,7 @@ public class PropertiesConfigurationTest {
}
@Test
- public void testConsoleAppenderFilter() throws Exception {
+ public void testFilter() throws Exception {
try (LoggerContext loggerContext = TestConfigurator.configure("target/test-classes/LOG4J2-3247.properties")) {
// LOG4J2-3281 PropertiesConfiguration.buildAppender not adding filters to appender
Configuration configuration = loggerContext.getConfiguration();
@@ -67,21 +67,6 @@ public class PropertiesConfigurationTest {
}
@Test
- public void testCustomAppenderFilter() throws Exception {
- try (LoggerContext loggerContext = TestConfigurator.configure("target/test-classes/LOG4J2-3281.properties")) {
- // LOG4J2-3281 PropertiesConfiguration.buildAppender not adding filters to appender
- Configuration configuration = loggerContext.getConfiguration();
- assertNotNull(configuration);
- Appender appender = configuration.getAppender("CUSTOM");
- assertNotNull(appender);
- Filterable filterable = (Filterable) appender;
- FilterAdapter filter = (FilterAdapter) filterable.getFilter();
- assertNotNull(filter);
- assertTrue(filter.getFilter() instanceof NeutralFilterFixture);
- }
- }
-
- @Test
public void testListAppender() throws Exception {
try (LoggerContext loggerContext = TestConfigurator.configure("target/test-classes/log4j1-list.properties")) {
Logger logger = LogManager.getLogger("test");
diff --git a/log4j-1.2-api/src/test/resources/LOG4J2-3281.properties b/log4j-1.2-api/src/test/resources/LOG4J2-3281.properties
deleted file mode 100644
index 4a45fd5..0000000
--- a/log4j-1.2-api/src/test/resources/LOG4J2-3281.properties
+++ /dev/null
@@ -1,25 +0,0 @@
-# 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.config.NeutralFilterFixture
-log4j.appender.CUSTOM.filter.1.onMatch=neutral
-log4j.appender.CUSTOM.Target=System.out
-log4j.appender.CUSTOM.layout=org.apache.log4j.PatternLayout
-log4j.appender.CUSTOM.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
-
-log4j.logger.org.apache.log4j.xml=trace, CUSTOM
-log4j.rootLogger=trace, CUSTOM