Log4j SMTPAppender
Our current project is due for another release to production very soon. Last week Tom added another appender into our log4j configuration for our UAT enviroment. This appender is an SMTPAppender and it sends emails to a group list for our project team. This new appender is set to the ERROR severity. The configuration for this appender looks like this:
log4j.appender.email.From=me@email
log4j.appender.email.To=us@email
log4j.appender.email.Subject=[AppName] UAT Exception
log4j.appender.email.SMTPHost=host
log4j.appender.email.SMTPUsername=user
log4j.appender.email.SMTPPassword=pass
log4j.appender.email.layout=org.apache.log4j.PatternLayout
log4j.appender.email.layout.ConversionPattern=%d{ISO8601} %-5p [%t %x] [%c{1}] – %m%n
log4j.appender.email.Threshold=ERROR
As of this morning we had recevied 17 emails from UAT. There were 8 types of errors and the most occurrences of any one type of error was 6. We always had access to this information in the log files of course, but getting the emails has had several advantages:
- The emails draw your attention – the visibility of problems in UAT has been increase.
- We’re more inclined to investigate the cause of the error/exception earlier. Previously the devs would generally only become aware of exceptions in UAT when one of our QAs asked one of us to take a look. Having the email going to all the devs also means that more people look at the exception and we are able to troubleshoot it more easily.
- It’s easier to group exception types – we can collect data about the exceptions more easily.
The plan is to include an SMTPAppender in the log4j configuration for our production environment. I think this is a very good idea and would recommend doing it.
This sounds good, but has one very important gotcha. As soon as you have a single problem that doesn’t get fixed, there will be a repeat email every time it goes wrong. At this point, most people will start ignoring or filtering these mails and are likely to miss any further issues.
I guess the broken windows theory really applies in this case, and you have to be very disciplined about fixing problems.
Adam Scott
October 22, 2009 at 4:25 pm