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/23 15:34:54 UTC
[logging-log4j2] branch release-2.x updated: [LOG4J2-3281] PropertiesConfiguration.buildAppender not adding filters to appender.
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 e176343 [LOG4J2-3281] PropertiesConfiguration.buildAppender not adding filters to appender.
e176343 is described below
commit e17634309ec64c3781dd04952fe0e7e6a8688144
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Dec 23 10:34:48 2021 -0500
[LOG4J2-3281] PropertiesConfiguration.buildAppender not adding filters
to appender.
Test building filters from a 1.2 properties file.
---
.../org/apache/log4j/bridge/FilterAdapter.java | 20 ++++++++++++++-----
...ilterFixture.java => NeutralFilterFixture.java} | 2 +-
.../log4j/config/PropertiesConfigurationTest.java | 23 +++++++++++++++++++++-
.../src/test/resources/LOG4J2-3247.properties | 2 +-
4 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/bridge/FilterAdapter.java b/log4j-1.2-api/src/main/java/org/apache/log4j/bridge/FilterAdapter.java
index 2dff272..adab346 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/bridge/FilterAdapter.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/bridge/FilterAdapter.java
@@ -33,11 +33,6 @@ public class FilterAdapter extends AbstractFilter {
}
@Override
- public void start() {
- filter.activateOptions();
- }
-
- @Override
public Result filter(LogEvent event) {
LoggingEvent loggingEvent = new LogEventAdapter(event);
Filter next = filter;
@@ -53,4 +48,19 @@ public class FilterAdapter extends AbstractFilter {
}
return Result.NEUTRAL;
}
+
+ /**
+ * Gets the actual filter.
+ *
+ * @return the actual filter.
+ * @since 2.17.1
+ */
+ public Filter getFilter() {
+ return filter;
+ }
+
+ @Override
+ public void start() {
+ filter.activateOptions();
+ }
}
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/ZeroFilterFixture.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/NeutralFilterFixture.java
similarity index 95%
rename from log4j-1.2-api/src/test/java/org/apache/log4j/config/ZeroFilterFixture.java
rename to log4j-1.2-api/src/test/java/org/apache/log4j/config/NeutralFilterFixture.java
index 64eead9..f6a20b2 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/ZeroFilterFixture.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/NeutralFilterFixture.java
@@ -22,7 +22,7 @@ import org.apache.log4j.spi.LoggingEvent;
/**
* A test fixture used by {@code src/test/resources/LOG4J2-3247.properties}.
*/
-public class ZeroFilterFixture extends Filter {
+public class NeutralFilterFixture extends Filter {
@Override
public int decide(LoggingEvent event) {
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 7dd768d..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
@@ -27,10 +27,12 @@ import org.apache.log4j.ListAppender;
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.spi.LoggingEvent;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.filter.Filterable;
import org.junit.Test;
/**
@@ -39,9 +41,28 @@ import org.junit.Test;
public class PropertiesConfigurationTest {
@Test
- public void testFilter() throws Exception {
+ public void testConfigureNullPointerException() throws Exception {
try (LoggerContext loggerContext = TestConfigurator.configure("target/test-classes/LOG4J2-3247.properties")) {
// [LOG4J2-3247] configure() should not throw an NPE.
+ Configuration configuration = loggerContext.getConfiguration();
+ assertNotNull(configuration);
+ Appender appender = configuration.getAppender("CONSOLE");
+ assertNotNull(appender);
+ }
+ }
+
+ @Test
+ 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();
+ assertNotNull(configuration);
+ Appender appender = configuration.getAppender("CONSOLE");
+ assertNotNull(appender);
+ Filterable filterable = (Filterable) appender;
+ FilterAdapter filter = (FilterAdapter) filterable.getFilter();
+ assertNotNull(filter);
+ assertTrue(filter.getFilter() instanceof NeutralFilterFixture);
}
}
diff --git a/log4j-1.2-api/src/test/resources/LOG4J2-3247.properties b/log4j-1.2-api/src/test/resources/LOG4J2-3247.properties
index 7bbb4bd..b1d76e1 100644
--- a/log4j-1.2-api/src/test/resources/LOG4J2-3247.properties
+++ b/log4j-1.2-api/src/test/resources/LOG4J2-3247.properties
@@ -15,7 +15,7 @@
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
-log4j.appender.CONSOLE.filter.1=org.apache.log4j.config.ZeroFilterFixture
+log4j.appender.CONSOLE.filter.1=org.apache.log4j.config.NeutralFilterFixture
log4j.appender.CONSOLE.filter.1.onMatch=neutral
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout