Thursday January 30, 2003
How To: Configure Log4j to notify you of errors
A couple of weeks ago, I mentioned that I was interested in using Log4j's SMTPAppender to e-mail me messages when errors occured in my webapp. I discovered how easy it is a couple of days ago. Here's how to configure it.
1. Add mail to the log4j.rootCategory in log4j.properties: log4j.rootCategory=INFO, stdout, mail
2. Add the following configuration settings to log4j.properties:
# Configuration for receiving e-mails when ERROR messages occur.
log4j.appender.mail=org.apache.log4j.net.SMTPAppender
log4j.appender.mail.To=@ERROR-MAILTO@
log4j.appender.mail.From=@ERROR-MAILFROM@
log4j.appender.mail.SMTPHost=@ERROR-MAILHOST@
log4j.appender.mail.Threshold=ERROR
log4j.appender.mail.BufferSize=1
log4j.appender.mail.Subject=CCT Application Error
log4j.appender.mail.layout=org.apache.log4j.PatternLayout
log4j.appender.mail.layout.ConversionPattern=%p [%t] %C{1}.%M(%L) | %m%n
One question I have is that the ConversionPattern is kinda funky - where the line breaks don't seem to be carried into the e-mail (from exception.printStackTrace()). Any suggestions for a better configuration are appreciated. The To, From, and SMTPHost are all replaced with values from Ant during the build process.
Posted in Java
at Jan 30 2003, 06:25:43 AM MST
2 Comments
Search This Site
Recent Entries
- What's Next
- Jack's Mohawk
- LinkedIn Cuts 10% (a.k.a. The Journey is Over)
- Happy Birthday Abbie!
- Moving from Spring's XML to Annotations in AppFuse
- Free Maven Training in New Orleans on Election Day
- AppFuse Light ยป AppFuse, Maven Archetypes and Shared Web Assets
- Great Weekend in Montana
- Colorado Software Summit 2008 Wrapup
- RESTful Web Applications with Subbu Allamaraju
Posted by Llucifer on January 30, 2003 at 07:25 AM MST #
Posted by Rajeev Chaturvedi on November 15, 2007 at 10:40 AM MST #