logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carn...@apache.org
Subject svn commit: r557351 - in /logging/log4j/companions/extras/trunk: ./ src/main/java/org/apache/log4j/filter/ src/main/java/org/apache/log4j/rolling/ src/test/java/org/apache/log4j/filter/ src/test/resources/org/apache/log4j/filter/
Date Wed, 18 Jul 2007 18:20:02 GMT
Author: carnold
Date: Wed Jul 18 11:20:01 2007
New Revision: 557351

URL: http://svn.apache.org/viewvc?view=rev&rev=557351
Log:
Bug 42099: Backport filter tests from log4j 1.3

Added:
    logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/filter/LoggerMatchFilter.java
      - copied unchanged from r557181, logging/log4j/trunk/src/main/java/org/apache/log4j/filter/LoggerMatchFilter.java
    logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter.11
      - copied unchanged from r557323, logging/log4j/trunk/tests/witness/filter/simpleFilter.11
    logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter.6
      - copied unchanged from r557181, logging/log4j/trunk/tests/witness/filter/simpleFilter.6
    logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter.7
      - copied unchanged from r557323, logging/log4j/trunk/tests/witness/filter/simpleFilter.7
    logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter.8
      - copied unchanged from r557181, logging/log4j/trunk/tests/witness/filter/simpleFilter.8
    logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter10.xml
      - copied, changed from r557323, logging/log4j/trunk/tests/input/filter/simpleFilter10.xml
    logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter11.xml
      - copied, changed from r557323, logging/log4j/trunk/tests/input/filter/simpleFilter11.xml
    logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter12.xml
      - copied, changed from r557323, logging/log4j/trunk/tests/input/filter/simpleFilter12.xml
    logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter6.xml
      - copied, changed from r557181, logging/log4j/trunk/tests/input/filter/simpleFilter6.xml
    logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter7.xml
      - copied, changed from r557181, logging/log4j/trunk/tests/input/filter/simpleFilter7.xml
    logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter8.xml
      - copied, changed from r557181, logging/log4j/trunk/tests/input/filter/simpleFilter8.xml
    logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter9.xml
      - copied, changed from r557323, logging/log4j/trunk/tests/input/filter/simpleFilter9.xml
Modified:
    logging/log4j/companions/extras/trunk/   (props changed)
    logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/filter/AndFilter.java
    logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/rolling/RollingConfigurator.java
    logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/SimpleFilterTest.java

Propchange: logging/log4j/companions/extras/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Jul 18 11:20:01 2007
@@ -4,6 +4,15 @@
 .classpath
 .project
 .settings
-apache-log4j-filters*
+apache-log4j-extras*
+test*
+sbr*
+size*
+filter*
+pattern*
+temp
+
+
+
 
 

Modified: logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/filter/AndFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/filter/AndFilter.java?view=diff&rev=557351&r1=557350&r2=557351
==============================================================================
--- logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/filter/AndFilter.java
(original)
+++ logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/filter/AndFilter.java
Wed Jul 18 11:20:01 2007
@@ -19,6 +19,12 @@
 
 import org.apache.log4j.spi.Filter;
 import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.OptionHandler;
+import org.apache.log4j.xml.UnrecognizedElementHandler;
+import org.apache.log4j.rolling.RollingConfigurator;
+import org.w3c.dom.Element;
+
+import java.util.Properties;
 
 
 /**
@@ -61,10 +67,13 @@
  * LEVEL == DEBUG && MSG ~= 'test'
  * or
  * ! ( LEVEL == DEBUG && MSG ~= 'test' )
- *  
+ *
+ * XML configuration of this filter requires use of either log4j 1.2.15 or later or
+ * org.apache.log4j.rolling.RollingConfigurator.
+ *
  * @author Scott Deboy sdeboy@apache.org
  */
-public class AndFilter extends Filter {
+public class AndFilter extends Filter implements UnrecognizedElementHandler {
   Filter headFilter = null;
   Filter tailFilter = null;
   boolean acceptOnMatch = true;
@@ -109,4 +118,22 @@
     }
     return Filter.NEUTRAL;
   }
+
+    /**
+     * {@inheritDoc}
+     */
+  public boolean parseUnrecognizedElement(final Element element,
+                                          final Properties props) throws Exception {
+      final String nodeName = element.getNodeName();
+      if ("filter".equals(nodeName)) {
+          OptionHandler filter = RollingConfigurator.parseElement(element, props, Filter.class);
+          if (filter instanceof Filter) {
+              filter.activateOptions();
+              this.addFilter((Filter) filter);
+          }
+          return true;
+      }
+      return false;
+  }
+
 }

Modified: logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/rolling/RollingConfigurator.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/rolling/RollingConfigurator.java?view=diff&rev=557351&r1=557350&r2=557351
==============================================================================
--- logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/rolling/RollingConfigurator.java
(original)
+++ logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/rolling/RollingConfigurator.java
Wed Jul 18 11:20:01 2007
@@ -36,7 +36,6 @@
 import org.apache.log4j.spi.LoggerRepository;
 import org.apache.log4j.spi.OptionHandler;
 import org.apache.log4j.spi.RendererSupport;
-import org.apache.log4j.xml.DOMConfigurator;
 import org.apache.log4j.xml.SAXErrorHandler;
 import org.apache.log4j.xml.UnrecognizedElementHandler;
 import org.w3c.dom.Document;
@@ -609,7 +608,7 @@
   static
   public
   void configure (Element element) {
-    DOMConfigurator configurator = new DOMConfigurator();
+    RollingConfigurator configurator = new RollingConfigurator();
     configurator.doConfigure(element,  LogManager.getLoggerRepository());
   }
 
@@ -790,7 +789,7 @@
   static
   public
   void configure(String filename) throws FactoryConfigurationError {
-    new DOMConfigurator().doConfigure(filename, 
+    new RollingConfigurator().doConfigure(filename,
 				      LogManager.getLoggerRepository());
   }
 
@@ -800,7 +799,7 @@
   static
   public
   void configure(URL url) throws FactoryConfigurationError {
-    new DOMConfigurator().doConfigure(url, LogManager.getLoggerRepository());
+    new RollingConfigurator().doConfigure(url, LogManager.getLoggerRepository());
   }
 
   /**

Modified: logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/SimpleFilterTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/SimpleFilterTest.java?view=diff&rev=557351&r1=557350&r2=557351
==============================================================================
--- logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/SimpleFilterTest.java
(original)
+++ logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/SimpleFilterTest.java
Wed Jul 18 11:20:01 2007
@@ -16,9 +16,7 @@
  */
 package org.apache.log4j.filter;
 
-import junit.framework.Test;
 import junit.framework.TestCase;
-import junit.framework.TestSuite;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.apache.log4j.util.Compare;
@@ -28,7 +26,8 @@
 import org.apache.log4j.util.LineNumberFilter;
 import org.apache.log4j.util.SunReflectFilter;
 import org.apache.log4j.util.Transformer;
-import org.apache.log4j.xml.DOMConfigurator;
+import org.apache.log4j.rolling.RollingConfigurator;
+import org.apache.log4j.xml.Log4jEntityResolver;
 import org.w3c.dom.Document;
 
 import javax.xml.parsers.DocumentBuilder;
@@ -52,6 +51,7 @@
   public final static String TEMP = "temp";
   
   static String TEST1_PAT = "(DEBUG|INFO|WARN|ERROR|FATAL) - Message \\d";
+  static String TEST8_PAT = "WARN org.apache.log4j.filter.SimpleFilterTest - Message \\d";
   static String EXCEPTION1 = "java.lang.Exception: Just testing";
   static String EXCEPTION2 = "\\s*at .*\\(.*:\\d{1,4}\\)";
   static String EXCEPTION3 = "\\s*at .*\\(Native Method\\)";
@@ -69,17 +69,21 @@
     root.getLoggerRepository().resetConfiguration();
   }
 
-  
-  public void test1() throws Exception {
-    InputStream is = getClass().getResourceAsStream("simpleFilter1.xml");
+  private final void configure(final String resourceName) throws Exception {
+    InputStream is = getClass().getResourceAsStream(resourceName);
     if (is == null) {
         throw new FileNotFoundException(
-                "Could not find resource simpleFilter1.xml");
+                "Could not find resource " + resourceName);
     }
     DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     DocumentBuilder builder = factory.newDocumentBuilder();
+	builder.setEntityResolver(new Log4jEntityResolver());
     Document doc = builder.parse(is);
-    DOMConfigurator.configure(doc.getDocumentElement());
+    RollingConfigurator.configure(doc.getDocumentElement());
+  }
+  
+  public void test1() throws Exception {
+    configure("simpleFilter1.xml");
 
     common();
     
@@ -95,6 +99,112 @@
              FILTERED,
              "witness/filter/simpleFilter.1"));
   }
+
+    public void test6() throws Exception {
+      configure("simpleFilter6.xml");
+      common();
+
+      ControlFilter cf = new ControlFilter(new String[]{TEST1_PAT, EXCEPTION1, EXCEPTION2,
EXCEPTION3});
+
+
+      Transformer.transform(TEMP, FILTERED, new Filter[] {cf,
+          new LineNumberFilter(),
+          new SunReflectFilter(),
+          new JunitTestRunnerFilter()});
+
+       assertTrue(Compare.compare(SimpleFilterTest.class, FILTERED, "witness/filter/simpleFilter.6"));
+    }
+
+    public void test7() throws Exception {
+      configure("simpleFilter7.xml");
+      common();
+
+      ControlFilter cf = new ControlFilter(new String[]{TEST1_PAT, EXCEPTION1, EXCEPTION2,
EXCEPTION3});
+
+
+      Transformer.transform(TEMP, FILTERED, new Filter[] {cf,
+          new LineNumberFilter(),
+          new SunReflectFilter(),
+          new JunitTestRunnerFilter()});
+
+       assertTrue(Compare.compare(SimpleFilterTest.class, FILTERED, "witness/filter/simpleFilter.7"));
+    }
+
+    public void test8() throws Exception {
+      configure("simpleFilter8.xml");
+      common();
+
+      ControlFilter cf = new ControlFilter(new String[]{TEST8_PAT, EXCEPTION1, EXCEPTION2,
EXCEPTION3});
+
+
+      Transformer.transform(TEMP, FILTERED, new Filter[] {cf,
+          new LineNumberFilter(),
+          new SunReflectFilter(),
+          new JunitTestRunnerFilter()});
+
+       assertTrue(Compare.compare(SimpleFilterTest.class, FILTERED, "witness/filter/simpleFilter.8"));
+    }
+
+    public void test9() throws Exception {
+      configure("simpleFilter9.xml");
+      common();
+
+      ControlFilter cf = new ControlFilter(new String[]{TEST1_PAT, EXCEPTION1, EXCEPTION2,
EXCEPTION3});
+
+
+      Transformer.transform(TEMP, FILTERED, new Filter[] {cf,
+          new LineNumberFilter(),
+          new SunReflectFilter(),
+          new JunitTestRunnerFilter()});
+
+       assertTrue(Compare.compare(SimpleFilterTest.class, FILTERED, "witness/filter/simpleFilter.1"));
+    }
+
+    public void test10() throws Exception {
+      configure("simpleFilter10.xml");
+      common();
+
+      ControlFilter cf = new ControlFilter(new String[]{TEST1_PAT, EXCEPTION1, EXCEPTION2,
EXCEPTION3});
+
+
+      Transformer.transform(TEMP, FILTERED, new Filter[] {cf,
+          new LineNumberFilter(),
+          new SunReflectFilter(),
+          new JunitTestRunnerFilter()});
+
+       assertTrue(Compare.compare(SimpleFilterTest.class, FILTERED, "witness/filter/simpleFilter.6"));
+    }
+
+    public void test11() throws Exception {
+      configure("simpleFilter11.xml");
+      common();
+
+      ControlFilter cf = new ControlFilter(new String[]{TEST1_PAT, EXCEPTION1, EXCEPTION2,
EXCEPTION3});
+
+
+      Transformer.transform(TEMP, FILTERED, new Filter[] {cf,
+          new LineNumberFilter(),
+          new SunReflectFilter(),
+          new JunitTestRunnerFilter()});
+
+       assertTrue(Compare.compare(SimpleFilterTest.class, FILTERED, "witness/filter/simpleFilter.11"));
+    }
+
+    public void test12() throws Exception {
+      configure("simpleFilter12.xml");
+      common();
+
+      ControlFilter cf = new ControlFilter(new String[]{TEST8_PAT, EXCEPTION1, EXCEPTION2,
EXCEPTION3});
+
+
+      Transformer.transform(TEMP, FILTERED, new Filter[] {cf,
+          new LineNumberFilter(),
+          new SunReflectFilter(),
+          new JunitTestRunnerFilter()});
+
+       assertTrue(Compare.compare(SimpleFilterTest.class, FILTERED, "witness/filter/simpleFilter.8"));
+    }
+
   
   void common() {
     int i = -1;
@@ -122,10 +232,4 @@
     root.error("Message " + i, e);    
   }
   
-  public static Test suite() {
-    TestSuite suite = new TestSuite();
-    suite.addTest(new SimpleFilterTest("test1"));
-    return suite;
-   }
-
 }

Copied: logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter10.xml
(from r557323, logging/log4j/trunk/tests/input/filter/simpleFilter10.xml)
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter10.xml?view=diff&rev=557351&p1=logging/log4j/trunk/tests/input/filter/simpleFilter10.xml&r1=557323&p2=logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter10.xml&r2=557351
==============================================================================
--- logging/log4j/trunk/tests/input/filter/simpleFilter10.xml (original)
+++ logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter10.xml
Wed Jul 18 11:20:01 2007
@@ -22,7 +22,7 @@
 
   <appender name="TEMP" class="org.apache.log4j.FileAppender">
     <param name="Append" value="false" />
-    <param name="File"   value="output/temp" />
+    <param name="File"   value="temp" />
     <layout class="org.apache.log4j.PatternLayout">
       <param name="ConversionPattern" value="%p - %m\n"/>
     </layout>

Copied: logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter11.xml
(from r557323, logging/log4j/trunk/tests/input/filter/simpleFilter11.xml)
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter11.xml?view=diff&rev=557351&p1=logging/log4j/trunk/tests/input/filter/simpleFilter11.xml&r1=557323&p2=logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter11.xml&r2=557351
==============================================================================
--- logging/log4j/trunk/tests/input/filter/simpleFilter11.xml (original)
+++ logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter11.xml
Wed Jul 18 11:20:01 2007
@@ -23,7 +23,7 @@
 
   <appender name="TEMP" class="org.apache.log4j.FileAppender">
     <param name="Append" value="false" />
-    <param name="File"   value="output/temp" />
+    <param name="File"   value="temp" />
     <layout class="org.apache.log4j.PatternLayout">
       <param name="ConversionPattern"
 	value="%p - %m\n"/>

Copied: logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter12.xml
(from r557323, logging/log4j/trunk/tests/input/filter/simpleFilter12.xml)
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter12.xml?view=diff&rev=557351&p1=logging/log4j/trunk/tests/input/filter/simpleFilter12.xml&r1=557323&p2=logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter12.xml&r2=557351
==============================================================================
--- logging/log4j/trunk/tests/input/filter/simpleFilter12.xml (original)
+++ logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter12.xml
Wed Jul 18 11:20:01 2007
@@ -23,7 +23,7 @@
 
   <appender name="TEMP" class="org.apache.log4j.FileAppender">
     <param name="Append" value="false" />
-    <param name="File"   value="output/temp" />
+    <param name="File"   value="temp" />
     <layout class="org.apache.log4j.PatternLayout">
       <param name="ConversionPattern"
 	value="%p %c - %m\n"/>

Copied: logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter6.xml
(from r557181, logging/log4j/trunk/tests/input/filter/simpleFilter6.xml)
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter6.xml?view=diff&rev=557351&p1=logging/log4j/trunk/tests/input/filter/simpleFilter6.xml&r1=557181&p2=logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter6.xml&r2=557351
==============================================================================
--- logging/log4j/trunk/tests/input/filter/simpleFilter6.xml (original)
+++ logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter6.xml
Wed Jul 18 11:20:01 2007
@@ -22,7 +22,7 @@
 
   <appender name="TEMP" class="org.apache.log4j.FileAppender">
     <param name="Append" value="false" />
-    <param name="File"   value="output/temp" />
+    <param name="File"   value="temp" />
     <layout class="org.apache.log4j.PatternLayout">
       <param name="ConversionPattern" value="%p - %m\n"/>
     </layout>

Copied: logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter7.xml
(from r557181, logging/log4j/trunk/tests/input/filter/simpleFilter7.xml)
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter7.xml?view=diff&rev=557351&p1=logging/log4j/trunk/tests/input/filter/simpleFilter7.xml&r1=557181&p2=logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter7.xml&r2=557351
==============================================================================
--- logging/log4j/trunk/tests/input/filter/simpleFilter7.xml (original)
+++ logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter7.xml
Wed Jul 18 11:20:01 2007
@@ -23,7 +23,7 @@
 
   <appender name="TEMP" class="org.apache.log4j.FileAppender">
     <param name="Append" value="false" />
-    <param name="File"   value="output/temp" />
+    <param name="File"   value="temp" />
     <layout class="org.apache.log4j.PatternLayout">
       <param name="ConversionPattern"
 	value="%p - %m\n"/>

Copied: logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter8.xml
(from r557181, logging/log4j/trunk/tests/input/filter/simpleFilter8.xml)
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter8.xml?view=diff&rev=557351&p1=logging/log4j/trunk/tests/input/filter/simpleFilter8.xml&r1=557181&p2=logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter8.xml&r2=557351
==============================================================================
--- logging/log4j/trunk/tests/input/filter/simpleFilter8.xml (original)
+++ logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter8.xml
Wed Jul 18 11:20:01 2007
@@ -23,7 +23,7 @@
 
   <appender name="TEMP" class="org.apache.log4j.FileAppender">
     <param name="Append" value="false" />
-    <param name="File"   value="output/temp" />
+    <param name="File"   value="temp" />
     <layout class="org.apache.log4j.PatternLayout">
       <param name="ConversionPattern"
 	value="%p %c - %m\n"/>

Copied: logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter9.xml
(from r557323, logging/log4j/trunk/tests/input/filter/simpleFilter9.xml)
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter9.xml?view=diff&rev=557351&p1=logging/log4j/trunk/tests/input/filter/simpleFilter9.xml&r1=557323&p2=logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter9.xml&r2=557351
==============================================================================
--- logging/log4j/trunk/tests/input/filter/simpleFilter9.xml (original)
+++ logging/log4j/companions/extras/trunk/src/test/resources/org/apache/log4j/filter/simpleFilter9.xml
Wed Jul 18 11:20:01 2007
@@ -23,7 +23,7 @@
   <appender name="A1" class="org.apache.log4j.FileAppender">
 
     <param name="Append" value="false" />
-    <param name="File"   value="output/temp" />
+    <param name="File"   value="temp" />
 
     <layout class="org.apache.log4j.PatternLayout">
       <param name="ConversionPattern" value="%p - %m\n"/>



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message