[logback-user] SMTPAppender with level WARN?

Joop Vriend joop.vriend at ddnh.nl
Mon Oct 20 22:06:33 CEST 2008


I'm trying to configure logback with an SMTPAppender that mails *every*
log message of level WARN or higher, but I can't get it working.

I've tried to use a (Threshold)filter, but that didn't work. (Why can't
you just use filters with SMTPAppender?!?)

I've tried to use an EvaluatorFilter with an expression 'level >= WARN',
but that didn't work either.

Now I'm trying to use a custom evaluator, but still can't get it
working... :-(  Level ERROR is being e-mailed, but other levels not.
For testing purposes I (even) wrote a custom evaluator-class that always
returns 'true' in it's evaluate()-method:

public class AlwaysTrueEvaluator extends ContextAwareBase implements
   String  name;
   boolean started;

   public boolean evaluate(Object event) throws NullPointerException,
     return true;

   public void setName(String name)
     this.name = name;

   public String getName()
     return name;

   public boolean isStarted()
     return started;

   public void start()
     started = true;

   public void stop()
     started = false;


This is my logback.xml file:


   <appender name="RootFileAppender"
     <filter class="ch.qos.logback.classic.filter.ThresholdFilter">

     <layout class="ch.qos.logback.classic.PatternLayout">
       <pattern>%date{yyyy-MM-dd HH:mm:ss}  %class %method
\(%file:%line\)%n  %level: %message%n</pattern>

   <appender name="RootEmailAppender"
     <subject>logback logrecord</subject>
     <layout class="ch.qos.logback.classic.PatternLayout">
       <pattern>%date{yyyy-MM-dd HH:mm:ss}  %class %method
\(%file:%line\)%n  %level: %message%n</pattern>
     <evaluator class="packagename.AlwaysTrueEvaluator"/>

     <level value ="debug"/>
     <appender-ref ref="RootFileAppender"/>
     <appender-ref ref="RootEmailAppender"/>


I'm using logback 0.9.9 with slf4j 1.5.5 on Tomcat 6.0.

Any help is greatly appreciated!

Kind regards, Joop Vriend.

More information about the Logback-user mailing list