logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1482079 - in /logging/log4j/log4j2/trunk: core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/ core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/ core/src/test/resources/ src/changes/
Date Mon, 13 May 2013 20:21:58 GMT
Author: rgoers
Date: Mon May 13 20:21:57 2013
New Revision: 1482079

URL: http://svn.apache.org/r1482079
Log:
LOG4J2-244 - Rewrite Appender was ignoring filters on referenced appenders.

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppenderTest.java
    logging/log4j/log4j2/trunk/core/src/test/resources/log4j-rewrite.xml
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java?rev=1482079&r1=1482078&r2=1482079&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java
Mon May 13 20:21:57 2013
@@ -61,7 +61,9 @@ public final class RewriteAppender<T ext
             final String name = ref.getRef();
             final Appender appender = map.get(name);
             if (appender != null) {
-                appenders.put(name, new AppenderControl(appender, ref.getLevel(), null));
+                Filter filter = appender instanceof AbstractAppender<?> ?
+                    ((AbstractAppender<?>) appender).getFilter() : null;
+                appenders.put(name, new AppenderControl(appender, ref.getLevel(), filter));
             } else {
                 LOGGER.error("Appender " + ref + " cannot be located. Reference ignored");
             }

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppenderTest.java?rev=1482079&r1=1482078&r2=1482079&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppenderTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppenderTest.java
Mon May 13 20:21:57 2013
@@ -37,6 +37,7 @@ import java.util.List;
 import java.util.Map;
 
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertEquals;
@@ -104,4 +105,22 @@ public class RewriteAppenderTest {
         assertTrue("Incorrect number of events. Expected 1, got " + list.size(), list.size()
== 1);
         assertFalse("Did not resolve user name", list.get(0).contains("{user.dir}"));
     }
+
+
+    @Test
+    public void testFilter() {
+        StructuredDataMessage msg = new StructuredDataMessage("Test", "This is a test", "Service");
+        msg.put("Key1", "Value2");
+        msg.put("Key2", "Value1");
+        Logger logger = LogManager.getLogger("org.apache.logging.log4j.core.Logging");
+        logger.debug(msg);
+        msg = new StructuredDataMessage("Test", "This is a test", "Service");
+        msg.put("Key1", "Value1");
+        msg.put("Key2", "Value2");
+        logger.trace(msg);
+
+        final List<LogEvent> list = app.getEvents();
+        assertTrue("Events were generated", list == null || list.size() == 0);
+        app.clear();
+    }
 }

Modified: logging/log4j/log4j2/trunk/core/src/test/resources/log4j-rewrite.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/log4j-rewrite.xml?rev=1482079&r1=1482078&r2=1482079&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/resources/log4j-rewrite.xml (original)
+++ logging/log4j/log4j2/trunk/core/src/test/resources/log4j-rewrite.xml Mon May 13 20:21:57
2013
@@ -42,6 +42,16 @@
       </PropertiesRewritePolicy>
       <appender-ref ref="List2"/>
     </Rewrite>
+    <Rewrite name="Rewrite3">
+      <MapFilter>
+        <KeyValuePair key="Key1" Value="Value1"/>
+      </MapFilter>
+      <MapRewritePolicy>
+        <KeyValuePair key="Key1" Value="Apache"/>
+        <KeyValuePair key="Key3" Value="Log4j"/>
+      </MapRewritePolicy>
+      <appender-ref ref="List"/>
+    </Rewrite>
   </appenders>
 
   <loggers>
@@ -49,6 +59,9 @@
       <appender-ref ref="Rewrite"/>
     </logger>
 
+    <logger name="org.apache.logging.log4j.core.Logging" level="trace" additivity="false">
+      <appender-ref ref="Rewrite3"/>
+    </logger>
     <logger name="org.apache.logging.log4j" level="trace" additivity="false">
       <appender-ref ref="Rewrite2"/>
     </logger>

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1482079&r1=1482078&r2=1482079&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Mon May 13 20:21:57 2013
@@ -22,6 +22,9 @@
   </properties>
   <body>
     <release version="2.0-beta7" date="2013-??-??" description="Bug fixes and enhancements">
+      <action issue="LOG4J-244" dev="rgoers" type="fix">
+        Rewrite Appender was ignoring filters on referenced appenders.
+      </action>
       <action issue="LOG4J2-245" dev="rgoers" type="fix">
         Avoid EmptyStack exception if getCallerClass and SecurityManager are not available.
       </action>



Mime
View raw message