On Aug 14, 2007, at 11:44 AM, WALLIS, Simon, GBM wrote:

Hi,



I have downloaded the log4j extras companion from
http://people.apache.org/builds/logging/log4j/companions/extras/1.0/
<http://people.apache.org/builds/logging/log4j/companions/extras/ 1.0/> and I am trying to use an Expression Filter with log4j 1.2.13. I have added the
apache-log4j-extras-1.0.jar to my classpath. But, for the life of me I
cannot get it to work.



Here is my appender config where I'm trying to use the Expression Filter.


...


It just seems to halt on load and doesn't give me any error message. Here is
the log4j debug output. You will see it just halts after parsing the
convertInFixToPostFix property.



log4j: Class name: [org.apache.log4j.net.SMTPAppender]

log4j: Setting property [SMTPHost] to [blah].

log4j: Setting property [from] to [EMAIL PROTECTED] ].

log4j: Setting property [to] to [EMAIL PROTECTED] ].

log4j: Setting property [subject] to [my subject].

log4j: Setting property [bufferSize] to [50].

log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"

log4j: Setting property [conversionPattern] to [%d{yyyy-MM-dd HH:mm:ss,SSS}
%5p %c{1}:%L - %m%n].

log4j: Setting property [expression] to [msg ~= blah].

log4j: Setting property [acceptOnMatch] to [true].

log4j: Setting property [convertInFixToPostFix] to [true].



..

Thanks for the feedback. I've tried but haven't been able to reproduce the problem. The log that I'm getting looks like:


log4j: Threshold ="".
log4j: Class name: [org.apache.log4j.net.SMTPAppender]
log4j: Setting property [SMTPHost] to [blah].
log4j: Setting property [from] to [EMAIL PROTECTED] ].
log4j: Setting property [to] to [EMAIL PROTECTED] ].
log4j: Setting property [subject] to [my subject].
log4j: Setting property [bufferSize] to [50].
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n].
log4j: Setting property [expression] to [msg ~= blah].
log4j: Setting property [acceptOnMatch] to [true].
log4j: Setting property [convertInFixToPostFix] to [true].
log4j: Adding filter of type [class org.apache.log4j.filter.ExpressionFilter] to appender named [SMTPAppender]. log4j: Adding filter of type [class org.apache.log4j.filter.DenyAllFilter] to appender named [SMTPAppender].
log4j: Adding appender named [SMTPAppender] to category [root].
log4j: Level value for root is  [DEBUG].
log4j: root level set to DEBUG
Disconnected from the target VM, address: '127.0.0.1:56913', transport: 'socket'

The next major event that follows "Setting property [convertInFixToPostFix]" that ends your log should be the call to propSetter.activate() in DOMConfigurator.parseFilters. The propSetter.activate() call should in turn call ExpressionFilter.activateOptions(). If that had succeeded, then you should have seen the "Adding filter of type ...ExpressionFilter" message from the line following the propSetter.activateCall(). If you can set a breakpoint on the propSetter.activate call and then step-into, hopefully you can get an indication of what is going wrong.

I made up a test case that parses an configuration file with your snippet of configuration code. To apply

cd apache-log4j-extras-1.0
echo "" > src/test/resource/org/apache/log4j/filter/filteredsmtp.xml
patch -p 1 -i extras.patch

where extras.patch contains

diff -u -r apache-log4j-extras-1.0/pom.xml apache-log4j-extras- patched/pom.xml
--- apache-log4j-extras-1.0/pom.xml     2007-06-30 01:09:21.000000000 -0500
+++ apache-log4j-extras-patched/pom.xml 2007-08-14 19:01:50.000000000 -0500
@@ -180,9 +180,14 @@
     <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
-      <version>1.2.9</version>
-    </dependency>
-       <dependency>
+      <version>1.2.13</version>
+    </dependency>
+      <dependency>
+        <groupId>javax.mail</groupId>
+        <artifactId>mail</artifactId>
+        <version>1.4</version>
+      </dependency>
+    <dependency>
       <groupId>oro</groupId>
       <artifactId>oro</artifactId>
       <version>2.0.8</version>
diff -u -r apache-log4j-extras-1.0/src/test/java/org/apache/log4j/ filter/SimpleFilterTest.java apache-log4j-extras-patched/src/test/ java/org/apache/log4j/filter/SimpleFilterTest.java --- apache-log4j-extras-1.0/src/test/java/org/apache/log4j/filter/ SimpleFilterTest.java 2007-06-30 01:09:13.000000000 -0500 +++ apache-log4j-extras-patched/src/test/java/org/apache/log4j/filter/ SimpleFilterTest.java 2007-08-14 19:13:33.000000000 -0500
@@ -21,6 +21,7 @@
import junit.framework.TestSuite;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
+import org.apache.log4j.Appender;
import org.apache.log4j.util.Compare;
import org.apache.log4j.util.ControlFilter;
import org.apache.log4j.util.Filter;
@@ -29,6 +30,7 @@
import org.apache.log4j.util.SunReflectFilter;
import org.apache.log4j.util.Transformer;
import org.apache.log4j.xml.DOMConfigurator;
+import org.apache.log4j.xml.Log4jEntityResolver;
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilder;
@@ -69,6 +71,26 @@
     root.getLoggerRepository().resetConfiguration();
   }
+    public void test13() throws Exception {
+        String resourceName = "filteredsmtp.xml";
+        InputStream is = getClass().getResourceAsStream(resourceName);
+        if (is == null) {
+            throw new FileNotFoundException(
+                    "Could not find resource " + resourceName);
+        }
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        DocumentBuilder builder = factory.newDocumentBuilder();
+        builder.setEntityResolver(new Log4jEntityResolver());
+        Document doc = builder.parse(is);
+ org.apache.log4j.xml.DOMConfigurator.configure (doc.getDocumentElement()); + Appender smtpAppender = Logger.getRootLogger().getAppender ("SMTPAppender");
+        assertNotNull(smtpAppender);
+        org.apache.log4j.spi.Filter filter = smtpAppender.getFilter();
+ assertTrue(filter instanceof org.apache.log4j.filter.ExpressionFilter);
+        org.apache.log4j.spi.Filter filter2 = filter.getNext();
+ assertTrue(filter2 instanceof org.apache.log4j.filter.DenyAllFilter);
+    }
+

   public void test1() throws Exception {
InputStream is = getClass().getResourceAsStream ("simpleFilter1.xml");
@@ -122,10 +144,4 @@
     root.error("Message " + i, e);
   }

-  public static Test suite() {
-    TestSuite suite = new TestSuite();
-    suite.addTest(new SimpleFilterTest("test1"));
-    return suite;
-   }
-
}
diff -u -r apache-log4j-extras-1.0/src/test/resources/org/apache/ log4j/filter/filteredsmtp.xml apache-log4j-extras-patched/src/test/ resources/org/apache/log4j/filter/filteredsmtp.xml --- apache-log4j-extras-1.0/src/test/resources/org/apache/log4j/ filter/filteredsmtp.xml 2007-08-14 19:20:20.000000000 -0500 +++ apache-log4j-extras-patched/src/test/resources/org/apache/log4j/ filter/filteredsmtp.xml 2007-08-14 19:01:49.000000000 -0500
@@ -1 +1,47 @@
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"; debug="true">
+<appender name="SMTPAppender"
+class="org.apache.log4j.net.SMTPAppender">
+
+            <param name="SMTPHost" value="blah"/>
+
+            <param name="From" value="[EMAIL PROTECTED] "/>
+
+            <param name="To" value="[EMAIL PROTECTED] "/>
+
+            <param name="Subject" value="my subject"/>
+
+            <param name="BufferSize" value="50" />
+
+            <layout class="org.apache.log4j.PatternLayout">
+
+                        <param name="ConversionPattern"
+value="%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n"/>
+
+            </layout>
+
+            <filter
+class="org.apache.log4j.filter.ExpressionFilter">
+
+                        <param name="Expression" value="msg ~=
+blah" />
+
+                        <param name="AcceptOnMatch"
+value="true"/>
+
+                        <param name="ConvertInFixToPostFix"
+value="true"/>
+
+            </filter>
+
+            <filter
+class="org.apache.log4j.filter.DenyAllFilter"/>
+
+</appender>
+
+    <root>
+        <appender-ref ref="SMTPAppender"/>
+        <level value="DEBUG"/>
+    </root>
+
+</log4j:configuration>



To run, install Maven 2.0.7 on your path and then run "mvn test". You should get 339 test run and 0 errors or failures. target/ surefire-reports/org...SimpleFilterTest.txt should list two tests run or should contain details on the test failure on the new test.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to