javalogginglogbacksmtpappender

Logback SMTPAppender Limiting Rate


How can I limit the rate of emails a Logback SMTPAppender, so that it would email me at most once every n minutes?

I have setup my logging according to the Logback appender, but I don't quite see how it be configured or subclassed to implement that.

Is there a hidden feature? Did someone develop a subclass to handle this?


Solution

  • Based on the documentation it appears that the way to do this is to write an EventEvaluator (see example 4.14 and 4.15) which looks at the time stamp for each event to only accept an event when "enough time" has passed since the last event was accepted.

    You can use System.currentTimeMillis to get a number you can do math on to calculate time differences. http://java.sun.com/javase/6/docs/api/java/lang/System.html#currentTimeMillis%28%29