Log4j 1.0.4

org.apache.log4j.net
Class SMTPAppender

java.lang.Object
  |
  +--org.apache.log4j.AppenderSkeleton
        |
        +--org.apache.log4j.net.SMTPAppender
All Implemented Interfaces:
Appender, OptionHandler

public class SMTPAppender
extends AppenderSkeleton

Send an e-mail when a specific logging event occurs, typically on errors or fatal errors.

The number of logging events delivered in this e-mail depend on the value of BufferSize option. The SMTPAppender keeps only the last BufferSize logging events in its cyclic buffer. This keeps memory requirements at a reasonable level while still delivering useful application context.

Since:
1.0
Author:
Ceki Gülcü

Field Summary
static String BUFFER_SIZE_OPTION
          A string constant used in naming the cyclic buffer size option.
static String EVALUATOR_CLASS_OPTION
          A string constant used in naming the class of the TriggeringEventEvaluator that this SMTPApepdner wll use.
static String FROM_OPTION
          A string constant used in naming the From field of outgoing e-mail output file.
static String LOCATION_INFO_OPTION
          A string constant used in naming the option for setting the the location information flag.
static String SMTP_HOST_OPTION
          A string constant used in naming the SMTP host that will be contacted to send the e-mail.
static String SUBJECT_OPTION
          A string constant used in naming the Subject field of outgoing e-mail output file.
static String TO_OPTION
          A string constant used in naming the To field of outgoing e-mail output file.
 
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold, THRESHOLD_OPTION
 
Constructor Summary
SMTPAppender()
          The default constructor will instantiate the appedner with a TriggeringEventEvaluator that will tirgger on events with priority ERROR or higher.
SMTPAppender(TriggeringEventEvaluator evaluator)
          Use evaluator passed as parameter as the TriggeringEventEvaluator for this SMTPAppender.
 
Method Summary
 void activateOptions()
          Derived appenders should override this method if option structure requires it.
 void append(LoggingEvent event)
          Perform SMTPAppender specific appending actions, mainly adding the event to a cyclic buffer and checking if the event triggers an e-mail to be sent.
protected  boolean checkEntryConditions()
          This method determines if there is a sense in attempting to append.
 void close()
          Release any resources allocated within the appender such as file handles, network connections, etc.
 String[] getOptionStrings()
          Retuns the option names for this component in addition in addition to the options of its super class AppenderSkeleton.
 boolean requiresLayout()
          The SMTPAppender requires a layout.
protected  void sendBuffer()
          Send the contents of the cyclic buffer as an e-mail message.
 void setOption(String option, String value)
          Set SMTPAppender specific options.
 
Methods inherited from class org.apache.log4j.AppenderSkeleton
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFirstFilter, getName, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TO_OPTION

public static final String TO_OPTION
A string constant used in naming the To field of outgoing e-mail output file. Current value of this string constant is To.

Note that all option keys are case sensitive.


FROM_OPTION

public static final String FROM_OPTION
A string constant used in naming the From field of outgoing e-mail output file. Current value of this string constant is From.

Note that all option keys are case sensitive.


SUBJECT_OPTION

public static final String SUBJECT_OPTION
A string constant used in naming the Subject field of outgoing e-mail output file. Current value of this string constant is Subject.

Note that all option keys are case sensitive.


SMTP_HOST_OPTION

public static final String SMTP_HOST_OPTION
A string constant used in naming the SMTP host that will be contacted to send the e-mail. Current value of this string constant is SMTPHost.

Note that all option keys are case sensitive.


BUFFER_SIZE_OPTION

public static final String BUFFER_SIZE_OPTION
A string constant used in naming the cyclic buffer size option. Current value of this string constant is BufferSize.

Note that all option keys are case sensitive.


EVALUATOR_CLASS_OPTION

public static final String EVALUATOR_CLASS_OPTION
A string constant used in naming the class of the TriggeringEventEvaluator that this SMTPApepdner wll use. Current value of this string constant is EvaluatorClass.

Note that all option keys are case sensitive.


LOCATION_INFO_OPTION

public static final String LOCATION_INFO_OPTION
A string constant used in naming the option for setting the the location information flag. Current value of this string constant is LocationInfo.

Note that all option keys are case sensitive.

Constructor Detail

SMTPAppender

public SMTPAppender()
The default constructor will instantiate the appedner with a TriggeringEventEvaluator that will tirgger on events with priority ERROR or higher.

SMTPAppender

public SMTPAppender(TriggeringEventEvaluator evaluator)
Use evaluator passed as parameter as the TriggeringEventEvaluator for this SMTPAppender.
Method Detail

activateOptions

public void activateOptions()
Description copied from class: AppenderSkeleton
Derived appenders should override this method if option structure requires it.
Overrides:
activateOptions in class AppenderSkeleton

append

public void append(LoggingEvent event)
Perform SMTPAppender specific appending actions, mainly adding the event to a cyclic buffer and checking if the event triggers an e-mail to be sent.
Overrides:
append in class AppenderSkeleton

checkEntryConditions

protected boolean checkEntryConditions()
This method determines if there is a sense in attempting to append.

It checks whether there is a set output target and also if there is a set layout. If these checks fail, then the boolean value false is returned.


close

public void close()
Description copied from interface: Appender
Release any resources allocated within the appender such as file handles, network connections, etc.

It is a programming error to append to a closed appender.


getOptionStrings

public String[] getOptionStrings()
Retuns the option names for this component in addition in addition to the options of its super class AppenderSkeleton.
Overrides:
getOptionStrings in class AppenderSkeleton

requiresLayout

public boolean requiresLayout()
The SMTPAppender requires a layout.

sendBuffer

protected void sendBuffer()
Send the contents of the cyclic buffer as an e-mail message.

setOption

public void setOption(String option,
                      String value)
Set SMTPAppender specific options.

On top of the options of the super class AppenderSkeleton, the recognized options are To, From, Subject, SMTPHost, BufferSize, EvaluatorClass and LocationInfo.

The To option takes a string value which should be a comma separated list of e-mail address of the recipients.

The From option takes a string value which should be a e-mail address of the sender.

The Subject option takes a string value which should be a the subject of the e-mail message.

The SMTPHost option takes a string value which should be a the host name of the SMTP server that will send the e-mail message.

The BufferSizeoption takes a positive integer representing the maximum number of logging events to collect in a cyclic buffer. When the BufferSize is reached, oldest events are deleted as new events are added to the buffer. By default the size of the cyclic buffer is 512 events.

The EvaluatorClass option takes a string value repsenting the name of the class implementing the TriggeringEventEvaluator interface. A corresponding object will be instantiated and assigned as the triggering event evaluator for the SMTPAppender.

The LocationInfo option takes a boolean value. By default, it is set to false which means there will be no effort to extract the location information related to the event. As a result, the layout that formats the events as they are sent out in an e-mail is likely to place the wrong location information (if present in the format).

Location information extraction is comparatively very slow and should be avoided unless performance is not a concern.

Overrides:
setOption in class AppenderSkeleton

Log4j 1.0.4

Please notify me about new log4j releases.