Friday, February 15th, 2008...10:43 am

Limiting log4j SMTPAppender

Jump to Comments

I wanted to set a maximum amount of e-mails that SMTPAppender would send after filling up a mailbox with 30,000 damn e-mails.

Turns out it was pretty damn easy, I set up my appender in a java class, and the SMTP appender has a method called setEvaluator that takes an instance of TriggeringEventEvaluator, so I just created a quick inner class like so.

class LimitingEvaluator implements TriggeringEventEvaluator
private int sentEvents = 0;
private int MAX_EVENTS = 20;
public boolean isTriggeringEvent(LoggingEvent arg0) {
if(sentEvents >= MAX_EVENTS)
return false;
return true;


and when i set up my appender I do this
appender.setEvaluator(new LimitingEvaluator());

1 Comment

Leave a Reply