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


Log4j.SMTPAppender



  • 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="org.apache.log4j.net.SMTPAppender">
<param name="SMTPHost" value="172.16.100.3" />
<param name="From" value="ChaiAvi@Chaiware.googlepages.com" />
<param name="To" value="Chaiavi@Chaiware.googlepages.com" />
<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" />
</layout>
</appender>


  • For a Property file use the following:
log4j.appender.mail=org.apache.log4j.net.SMTPAppender
#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.BufferSize=10
log4j.appender.mail.SMTPHost=172.16.100.3
log4j.appender.mail.From=ChaiaviS@Chaiware.googlepages.com
log4j.appender.mail.To=Chaiavi@Chaiware.googlepages.com
log4j.appender.mail.Subject=Bug Bug
# The Threshold only applies to the caching of the lesser than ERROR logs.
log4j.appender.mail.threshold=warn
log4j.appender.mail.layout=org.apache.log4j.PatternLayout
log4j.appender.mail.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

Comments

Popular posts from this blog

Profiling Java @ 2019

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

ZVR converter