logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1408625 - in /logging/log4j/log4j2/trunk: core/src/main/java/org/apache/logging/log4j/core/filter/ core/src/test/java/org/apache/logging/log4j/core/filter/ core/src/test/resources/ src/changes/
Date Tue, 13 Nov 2012 07:34:55 GMT
Author: rgoers
Date: Tue Nov 13 07:34:54 2012
New Revision: 1408625

URL: http://svn.apache.org/viewvc?rev=1408625&view=rev
Log:
LOG4J2-113 StructuredDataFilter annotated KeyValuePairs with PluginAttr instead of PluginElement

Added:
    logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-sdfilter.xml
      - copied, changed from r1408574, logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-mapfilter.xml
Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/filter/StructuredDataFilterTest.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java?rev=1408625&r1=1408624&r2=1408625&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java
Tue Nov 13 07:34:54 2012
@@ -22,6 +22,7 @@ import org.apache.logging.log4j.core.Log
 import org.apache.logging.log4j.core.Logger;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
 import org.apache.logging.log4j.core.helpers.KeyValuePair;
 import org.apache.logging.log4j.message.Message;
@@ -98,7 +99,7 @@ public final class StructuredDataFilter 
      * @return The StructuredDataFilter.
      */
     @PluginFactory
-    public static StructuredDataFilter createFilter(@PluginAttr("pairs") KeyValuePair[] pairs,
+    public static StructuredDataFilter createFilter(@PluginElement("pairs") KeyValuePair[]
pairs,
                                                     @PluginAttr("operator") String oper,
                                                     @PluginAttr("onmatch") String match,
                                                     @PluginAttr("onmismatch") String mismatch)
{

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/filter/StructuredDataFilterTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/filter/StructuredDataFilterTest.java?rev=1408625&r1=1408624&r2=1408625&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/filter/StructuredDataFilterTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/filter/StructuredDataFilterTest.java
Tue Nov 13 07:34:54 2012
@@ -17,11 +17,25 @@
 package org.apache.logging.log4j.core.filter;
 
 import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.Configurator;
 import org.apache.logging.log4j.core.helpers.KeyValuePair;
+import org.apache.logging.log4j.message.MapMessage;
 import org.apache.logging.log4j.message.StructuredDataMessage;
+import org.apache.logging.log4j.test.appender.ListAppender;
 import org.junit.Test;
 
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 /**
@@ -55,4 +69,21 @@ public class StructuredDataFilterTest {
         msg.put("ToAccount", "111111");
         assertTrue(filter.filter(null, Level.ERROR, null, msg, (Throwable)null) == Filter.Result.NEUTRAL);
     }
+
+    @Test
+    public void testConfig() {
+        LoggerContext ctx = Configurator.initialize("Test1", null, "target/test-classes/log4j2-sdfilter.xml");
+        Configuration config = ctx.getConfiguration();
+        Filter filter = config.getFilter();
+        assertNotNull("No StructuredDataFilter", filter);
+        assertTrue("Not a StructuredDataFilter", filter instanceof  StructuredDataFilter);
+        StructuredDataFilter sdFilter = (StructuredDataFilter) filter;
+        assertFalse("Should not be And filter", sdFilter.isAnd());
+        Map<String, List<String>> map = sdFilter.getMap();
+        assertNotNull("No Map", map);
+        assertTrue("No elements in Map", map.size() != 0);
+        assertTrue("Incorrect number of elements in Map", map.size() == 1);
+        assertTrue("Map does not contain key eventId", map.containsKey("eventId"));
+        assertTrue("List does not contain 2 elements", map.get("eventId").size() == 2);
+    }
 }

Copied: logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-sdfilter.xml (from r1408574,
logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-mapfilter.xml)
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-sdfilter.xml?p2=logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-sdfilter.xml&p1=logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-mapfilter.xml&r1=1408574&r2=1408625&rev=1408625&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-mapfilter.xml (original)
+++ logging/log4j/log4j2/trunk/core/src/test/resources/log4j2-sdfilter.xml Tue Nov 13 07:34:54
2012
@@ -17,10 +17,10 @@
 
 -->
 <configuration name="ConfigTest" status="error" packages="org.apache.logging.log4j.test">
-  <MapFilter onMatch="ACCEPT" onMismatch="NEUTRAL" operator="or">
+  <StructuredDataFilter onMatch="ACCEPT" onMismatch="NEUTRAL" operator="or">
     <KeyValuePair key="eventId" value="Login"/>
     <KeyValuePair key="eventId" value="Logout"/>
-  </MapFilter>
+  </StructuredDataFilter>
   <appenders>
     <List name="LIST">
       <PatternLayout pattern="%m%n"/>

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1408625&r1=1408624&r2=1408625&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Tue Nov 13 07:34:54 2012
@@ -23,6 +23,10 @@
 
   <body>
     <release version="2.0-beta4" date="TBD" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-113" dev="rgoers" type="fix">
+        StructuredDataFilter createFilter was annotated with PluginAttr instead of PluginElement
for the
+        KeyValuePairs.
+      </action>
       <action issue="LOG4J2-114" dev="rgoers" type="fix" due-to="Arkin Yetis">
         StructuredDataMessage was validating the length of the values in the event Map instead
of the lengths
         of the keys.



Mime
View raw message