SMTPAppender with level WARN?

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.

Hello Joop, Just after creating a/any logger, invoke the following method LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); StatusPrinter.print(lc); I *bet* the output will tell you went wrong. HTH, Joop Vriend wrote:
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.
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch

Hello Ceki, Thanks a lot for the very quick reply! You were right: the output contained an ERROR: 'Mandatory "name" attribute not set for <evaluator>'. The name-attribute is *not* mentioned in your CounterBasedEvaluator example in your Appender documentation: http://logback.qos.ch/manual/appenders.html#SMTPAppender And I couldn't find a XSD- or a DTD-file for the logback configuration. Now I added the name-attribute, but I get a different ERROR: Evaluator of type [packagename.AlwaysTrueEvaluator] is not of the desired type Again, I based my code on your CounterBasedEvaluator example. Any ideas? Thanks again, Joop. On 10/20/2008 10:16 PM, Ceki Gulcu wrote:
Hello Joop,
Just after creating a/any logger, invoke the following method
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); StatusPrinter.print(lc);
I *bet* the output will tell you went wrong.
HTH,
Joop Vriend wrote:
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.

Hello Ceki, I solved the ERROR "Evaluator of type [...] is not of the desired type" now by extending the class 'JaninoEventEvaluator' instead of 'ContextAwareBase'. But still messages of level lower than ERROR are not being mailed. It seems that the evaluate() method of my custom evaluator is not being called. Any ideas would greatly be appreciated! Thansk, Joop. On 10/20/2008 10:56 PM, Joop Vriend wrote:
Hello Ceki,
Thanks a lot for the very quick reply!
You were right: the output contained an ERROR: 'Mandatory "name" attribute not set for <evaluator>'.
The name-attribute is *not* mentioned in your CounterBasedEvaluator example in your Appender documentation:
http://logback.qos.ch/manual/appenders.html#SMTPAppender
And I couldn't find a XSD- or a DTD-file for the logback configuration.
Now I added the name-attribute, but I get a different ERROR:
Evaluator of type [packagename.AlwaysTrueEvaluator] is not of the desired type
Again, I based my code on your CounterBasedEvaluator example. Any ideas?
Thanks again, Joop.
On 10/20/2008 10:16 PM, Ceki Gulcu wrote:
Hello Joop,
Just after creating a/any logger, invoke the following method
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); StatusPrinter.print(lc);
I *bet* the output will tell you went wrong.
HTH,
Joop Vriend wrote:
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.
Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

Joop Vriend wrote:
You were right: the output contained an ERROR: 'Mandatory "name" attribute not set for <evaluator>'.
The name-attribute is *not* mentioned in your CounterBasedEvaluator example in your Appender documentation:
I'll correct that.
And I couldn't find a XSD- or a DTD-file for the logback configuration.
There is no XSD or DTD for the config files.
Now I added the name-attribute, but I get a different ERROR:
Evaluator of type [packagename.AlwaysTrueEvaluator] is not of the desired type
Is 'packagename' really the appropriate package name?
Again, I based my code on your CounterBasedEvaluator example. Any ideas?
Thanks again, Joop.
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch
participants (3)
-
Ceki Gulcu
-
Ceki Gulcu
-
Joop Vriend