jln646v jln646v - 2 months ago 36
Java Question

Logback SMTPAppender only sending last email

I am attempting to use

as my logging solution. I have an evaluator attached to the
that triggers an email to be sent every 100 errors logged. For the most part this works correctly, but I've noticed if I create errors rapidly in a loop to trigger multiple emails, only the last email gets sent, with the correct content. It seems to be a race condition where the first email is not finished being created/sent, and the second one overwrites the first on creation. Has anyone else experienced this or found a solution. My logback config is attached below.

<appender name="emailAppender" class="${logback.emailAppenderClass}">
<evaluator class="com.wdp.common.logging.logback.evaluators.CountingLoggerEvaulator">
<subject>Logback logs for facebook-ads-processes</subject>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d [Thread:%t] %p [%c] - %m%n</pattern>

<cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTracker">

This is the evaluator:

public class CountingLoggerEvaulator extends EventEvaluatorBase<ILoggingEvent> implements EventEvaluator<ILoggingEvent> {
//if limit is not set in configuration, this will cause it to send one email for each message received.
private int limit = 100;
private int counter = 0;

public void setLimit(int limit) {
this.limit = limit;

public int getLimit() {
return limit;

public boolean evaluate(ILoggingEvent expr) throws NullPointerException, EvaluationException {
if (counter == limit) {
counter = 0;
return true;
} else {
return false;

Any help is greatly appreciated.


The issue was the asynchronousSending attribute of the SMTPAppender defaults to true. I set it to false and it works properly