recently I was reading about Apache log4j appenders. and found log4j SMTPAppender which sends an e-mail when a specific logging event occurs, typically on errors or fatal errors. That time I got idea to write this post to send error logs through email using log4j SMTP appender.
for a developer error logs are very important. and it is very helpful for any developer to deliver error logs directly in their inbox.
So, you can add a simple SMTP appender entry in log4j configuration file and get error logs directly in your inbox.
Important!
for users using log4j.xml
<appender name=”mail” class=”org.apache.log4j.net.SMTPAppender”>
<param name=”BufferSize” value=”512″ />
<param name=”SMTPHost” value=”smtp.girishgaurav.com” />
<param name=”SMTPUsername” value=”no-reply@girishgaurav.com” />
<param name=”SMTPPassword” value=”password” />
<param name=”From” value=”no-reply@girishgaurav.com” />
<param name=”To” value=”blog@girishgaurav.com” />
<param name=”Subject” value=”Error detected on server” />
<layout class=”org.apache.log4j.PatternLayout”>
<param name=”ConversionPattern” value=”%d [%t] %-5p %c %x – %m%n” />
</layout>
<filter class=”org.apache.log4j.varia.LevelRangeFilter”>
<param name=”LevelMin” value=”error” />
<param name=”LevelMax” value=”fatal” />
</filter>
</appender>
Important!
for users using log4j.properties:
log4j.appender.mail=org.apache.log4j.net.SMTPAppender
log4j.appender.mail.BufferSize=512
log4j.appender.mail.SMTPHost=smtp.girishgaurav.com
log4j.appender.mail.SMTPUsername=no-reply@girishgaurav.com
log4j.appender.mail.SMTPPassword=password
log4j.appender.mail.From=no-reply@girishgaurav.com
log4j.appender.mail.To=blog@girishgaurav.com
log4j.appender.mail.Subject=Error detected on server
log4j.appender.mail.layout=org.apache.log4j.PatternLayout
log4j.appender.mail.layout.ConversionPattern=%d [%t] %-5p %c %x – %m%n
log4j.appender.mail.filter=org.apache.log4j.varia.LevelRangeFilter
log4j.appender.mail.filter.LevelMin=error
log4j.appender.mail.filter.LevelMax=fatel
References:
1 comment
1 ping
That’s really a cool feature. Thanks for sharing.