Do you want your Log4J to send you emails with notifications?


  • Include the following files in the Component’s Classpath: mail.jar and activation.jar.

  • This appender’s trigger for sending an alert email is ERROR or FATAL.

  • Lesser logs cannot be a trigger to send an email although they can be cached to be sent later on (bundled with a trigger level) when an ERROR / FATAL log occurs.

  • In order to enable lesser than ERROR level logs, two arguments should be defined: BufferSize and threshold.

  • For an XML file use the following lines:
<appender name="mail" class="">
<param name="SMTPHost" value="" />
<param name="From" value="" />
<param name="To" value="" />
<param name="Subject" value="[LOG] ..." />
<param name="BufferSize" value="2" />
<param name="threshold" value="INFO" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n" />

  • For a Property file use the following:
#If there is a large buffer it will cache the warn/info/debug messages too and when the ERROR message trigger happens it will bundle all of the messages together.
log4j.appender.mail.Subject=Bug Bug
# The Threshold only applies to the caching of the lesser than ERROR logs.
log4j.appender.mail.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n


Popular posts from this blog

Profiling Java @ 2019

Ant Explorer graphical Ant build tool

Shared/Pro/Managed Hosting for your site - which to choose ? (NO AFFILIATE LINKS!)