Save This Page
Home » slf4j-1.5.5 » org.apache » log4j » net » [javadoc | source]
org.apache.log4j.net
public class: SMTPAppender [javadoc | source]
java.lang.Object
   org.apache.log4j.AppenderSkeleton
      org.apache.log4j.net.SMTPAppender

All Implemented Interfaces:
    UnrecognizedElementHandler, OptionHandler, Appender

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. By default, an email message will be sent when an ERROR or higher severity message is appended. The triggering criteria can be modified by setting the evaluatorClass property with the name of a class implementing TriggeringEventEvaluator, setting the evaluator property with an instance of TriggeringEventEvaluator or nesting a triggeringPolicy element where the specified class implements TriggeringEventEvaluator.

Field Summary
protected  CyclicBuffer cb     
protected  Message msg     
protected  TriggeringEventEvaluator evaluator     
Fields inherited from org.apache.log4j.AppenderSkeleton:
layout,  name,  threshold,  errorHandler,  headFilter,  tailFilter,  closed
Constructor:
 public SMTPAppender() 
 public SMTPAppender(TriggeringEventEvaluator evaluator) 
Method from org.apache.log4j.net.SMTPAppender Summary:
activateOptions,   addressMessage,   append,   checkEntryConditions,   close,   createSession,   getAddress,   getBcc,   getBufferSize,   getCc,   getEvaluator,   getEvaluatorClass,   getFrom,   getLocationInfo,   getSMTPDebug,   getSMTPHost,   getSMTPPassword,   getSMTPUsername,   getSubject,   getTo,   parseAddress,   parseUnrecognizedElement,   requiresLayout,   sendBuffer,   setBcc,   setBufferSize,   setCc,   setEvaluator,   setEvaluatorClass,   setFrom,   setLocationInfo,   setSMTPDebug,   setSMTPHost,   setSMTPPassword,   setSMTPUsername,   setSubject,   setTo
Methods from org.apache.log4j.AppenderSkeleton:
activateOptions,   addFilter,   append,   clearFilters,   doAppend,   finalize,   getErrorHandler,   getFilter,   getFirstFilter,   getLayout,   getName,   getThreshold,   isAsSevereAsThreshold,   setErrorHandler,   setLayout,   setName,   setThreshold
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.log4j.net.SMTPAppender Detail:
 public  void activateOptions() 
    Activate the specified options, such as the smtp host, the recipient, from, etc.
 protected  void addressMessage(Message msg) throws MessagingException 
    Address message.
 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.
 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.

 public synchronized  void close() 
 protected Session createSession() 
    Create mail session.
 InternetAddress getAddress(String addressStr) 
 public String getBcc() 
    Get the bcc recipient addresses.
 public int getBufferSize() 
    Returns value of the BufferSize option.
 public String getCc() 
    Get the cc recipient addresses.
 public final TriggeringEventEvaluator getEvaluator() 
    Get triggering evaluator.
 public String getEvaluatorClass() 
    Returns value of the EvaluatorClass option.
 public String getFrom() 
    Returns value of the From option.
 public boolean getLocationInfo() 
    Returns value of the LocationInfo option.
 public boolean getSMTPDebug() 
    Get SMTP debug.
 public String getSMTPHost() 
    Returns value of the SMTPHost option.
 public String getSMTPPassword() 
    Get SMTP password.
 public String getSMTPUsername() 
    Get SMTP user name.
 public String getSubject() 
    Returns value of the Subject option.
 public String getTo() 
    Returns value of the To option.
 InternetAddress[] parseAddress(String addressStr) 
 public boolean parseUnrecognizedElement(Element element,
    Properties props) throws Exception 
    {@inheritDoc}
 public boolean requiresLayout() 
    The SMTPAppender requires a layout .
 protected  void sendBuffer() 
    Send the contents of the cyclic buffer as an e-mail message.
 public  void setBcc(String addresses) 
    Set the bcc recipient addresses.
 public  void setBufferSize(int bufferSize) 
    The BufferSize option 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.
 public  void setCc(String addresses) 
    Set the cc recipient addresses.
 public final  void setEvaluator(TriggeringEventEvaluator trigger) 
    Sets triggering evaluator.
 public  void setEvaluatorClass(String value) 
    The EvaluatorClass option takes a string value representing 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.
 public  void setFrom(String from) 
    The From option takes a string value which should be a e-mail address of the sender.
 public  void setLocationInfo(boolean locationInfo) 
    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.

 public  void setSMTPDebug(boolean debug) 
    Setting the SmtpDebug option to true will cause the mail session to log its server interaction to stdout. This can be useful when debuging the appender but should not be used during production because username and password information is included in the output.
 public  void setSMTPHost(String smtpHost) 
    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.
 public  void setSMTPPassword(String password) 
    The SmtpPassword option takes a string value which should be the password required to authenticate against the mail server.
 public  void setSMTPUsername(String username) 
    The SmtpUsername option takes a string value which should be the username required to authenticate against the mail server.
 public  void setSubject(String subject) 
    The Subject option takes a string value which should be a the subject of the e-mail message.
 public  void setTo(String to) 
    The To option takes a string value which should be a comma separated list of e-mail address of the recipients.