[logback-user] SMTPAppender with level WARN?

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


Hi,

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
EventEvaluator
{
   String  name;
   boolean started;


   public boolean evaluate(Object event) throws NullPointerException,
EvaluationException
   {
     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:


<configuration>

   <appender name="RootFileAppender"
class="ch.qos.logback.core.rolling.RollingFileAppender">
     <append>true</append>
     <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
       <level>debug</level>
     </filter>
     <rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

<fileNamePattern>${catalina.base}/logs/logback-root.%d{yyyy-MM-dd}.log.gz</fileNamePattern>
     </rollingPolicy>
     <layout class="ch.qos.logback.classic.PatternLayout">
       <pattern>%date{yyyy-MM-dd HH:mm:ss}  %class %method
\(%file:%line\)%n  %level: %message%n</pattern>
     </layout>
   </appender>

   <appender name="RootEmailAppender"
class="ch.qos.logback.classic.net.SMTPAppender">
     <bufferSize>1</bufferSize>
     <SMTPHost>_SMTP_HOST_</SMTPHost>
     <to>_TO_ADDRESS_</to>
     <from>_FROM_ADDRESS_</from>
     <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>
     </layout>
     <evaluator class="packagename.AlwaysTrueEvaluator"/>
   </appender>

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

</configuration>


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