Reputation: 32321
I'm using Apache Commons logging with a Java EE based application.
Is it possible that whenever there is an exception being logged, an alert is send via an email?
Upvotes: 0
Views: 477
Reputation: 88707
We're doing that whenever an error is logged. Here's the relevant part of our log4j configuration:
<appender name="SMTP" class="org.apache.log4j.net.SMTPAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="Threshold" value="ERROR"/>
<param name="To" value="[email protected]"/>
<param name="From" value="[email protected]"/>
<param name="Subject" value="Error"/>
<param name="SMTPHost" value="our.host"/>
<param name="BufferSize" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ABSOLUTE},%c] %m%n"/>
</layout>
</appender>
The logging itself is done using apache commons logging as a wrapper around log4j.
Note that you still might miss some exceptions if they are logged as warnings, but that should be intentional in that case and you'd normally not want to get an email every time an "expected" exception occurs.
Upvotes: 2