public class SMTPAppender extends AppenderSkeleton implements UnrecognizedElementHandler
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.
This class has implemented UnrecognizedElementHandler since 1.2.15.
Since 1.2.16, SMTP over SSL is supported by setting SMTPProtocol to "smpts".
限定符和类型 | 字段和说明 |
---|---|
protected CyclicBuffer |
cb |
protected TriggeringEventEvaluator |
evaluator |
protected javax.mail.Message |
msg |
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
构造器和说明 |
---|
SMTPAppender()
The default constructor will instantiate the appender with a
TriggeringEventEvaluator that will trigger on events with
level ERROR or higher. |
SMTPAppender(TriggeringEventEvaluator evaluator)
Use
evaluator passed as parameter as the TriggeringEventEvaluator for this SMTPAppender. |
限定符和类型 | 方法和说明 |
---|---|
void |
activateOptions()
Activate the specified options, such as the smtp host, the
recipient, from, etc.
|
protected void |
addressMessage(javax.mail.Message msg)
Address message.
|
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.
|
protected javax.mail.Session |
createSession()
Create mail session.
|
protected java.lang.String |
formatBody()
Layout body of email message.
|
java.lang.String |
getBcc()
Get the bcc recipient addresses.
|
int |
getBufferSize()
Returns value of the BufferSize option.
|
java.lang.String |
getCc()
Get the cc recipient addresses.
|
TriggeringEventEvaluator |
getEvaluator()
Get triggering evaluator.
|
java.lang.String |
getEvaluatorClass()
Returns value of the EvaluatorClass option.
|
java.lang.String |
getFrom()
Returns value of the From option.
|
boolean |
getLocationInfo()
Returns value of the LocationInfo option.
|
java.lang.String |
getReplyTo()
Get the reply addresses.
|
boolean |
getSendOnClose()
Get sendOnClose.
|
boolean |
getSMTPDebug()
Get SMTP debug.
|
java.lang.String |
getSMTPHost()
Returns value of the SMTPHost option.
|
java.lang.String |
getSMTPPassword()
Get SMTP password.
|
int |
getSMTPPort()
Get port.
|
java.lang.String |
getSMTPProtocol()
Get transport protocol.
|
java.lang.String |
getSMTPUsername()
Get SMTP user name.
|
java.lang.String |
getSubject()
Returns value of the Subject option.
|
java.lang.String |
getTo()
Returns value of the To option.
|
boolean |
parseUnrecognizedElement(org.w3c.dom.Element element,
java.util.Properties props)
Called to inform a configured object when
an unrecognized child element is encountered.
|
boolean |
requiresLayout()
The
SMTPAppender requires a layout . |
protected void |
sendBuffer()
Send the contents of the cyclic buffer as an e-mail message.
|
void |
setBcc(java.lang.String addresses)
Set the bcc recipient addresses.
|
void |
setBufferSize(int bufferSize)
The BufferSize option takes a positive integer
representing the maximum number of logging events to collect in a
cyclic buffer.
|
void |
setCc(java.lang.String addresses)
Set the cc recipient addresses.
|
void |
setEvaluator(TriggeringEventEvaluator trigger)
Sets triggering evaluator.
|
void |
setEvaluatorClass(java.lang.String value)
The EvaluatorClass option takes a string value
representing the name of the class implementing the
TriggeringEventEvaluator interface. |
void |
setFrom(java.lang.String from)
The From option takes a string value which should be a
e-mail address of the sender.
|
void |
setLocationInfo(boolean locationInfo)
The LocationInfo option takes a boolean value.
|
void |
setReplyTo(java.lang.String addresses)
Set the e-mail addresses to which replies should be directed.
|
void |
setSendOnClose(boolean val)
Set sendOnClose.
|
void |
setSMTPDebug(boolean debug)
Setting the SmtpDebug option to true will cause the mail session to log its server interaction to stdout.
|
void |
setSMTPHost(java.lang.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.
|
void |
setSMTPPassword(java.lang.String password)
The SmtpPassword option takes a string value which should be the password required to authenticate against
the mail server.
|
void |
setSMTPPort(int val)
Set port.
|
void |
setSMTPProtocol(java.lang.String val)
Set transport protocol.
|
void |
setSMTPUsername(java.lang.String username)
The SmtpUsername option takes a string value which should be the username required to authenticate against
the mail server.
|
void |
setSubject(java.lang.String subject)
The Subject option takes a string value which should be a
the subject of the e-mail message.
|
void |
setTo(java.lang.String to)
The To option takes a string value which should be a
comma separated list of e-mail address of the recipients.
|
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold
protected CyclicBuffer cb
protected javax.mail.Message msg
protected TriggeringEventEvaluator evaluator
public SMTPAppender()
TriggeringEventEvaluator
that will trigger on events with
level ERROR or higher.public SMTPAppender(TriggeringEventEvaluator evaluator)
evaluator
passed as parameter as the TriggeringEventEvaluator
for this SMTPAppender.public void activateOptions()
activateOptions
在接口中 OptionHandler
activateOptions
在类中 AppenderSkeleton
protected void addressMessage(javax.mail.Message msg) throws javax.mail.MessagingException
msg
- message, may not be null.javax.mail.MessagingException
- thrown if error addressing message.protected javax.mail.Session createSession()
public void append(LoggingEvent event)
append
在类中 AppenderSkeleton
protected boolean checkEntryConditions()
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 void close()
Appender
It is a programming error to append to a closed appender.
public java.lang.String getTo()
public boolean requiresLayout()
SMTPAppender
requires a layout
.requiresLayout
在接口中 Appender
protected java.lang.String formatBody()
protected void sendBuffer()
public java.lang.String getEvaluatorClass()
public java.lang.String getFrom()
public java.lang.String getReplyTo()
public java.lang.String getSubject()
public void setFrom(java.lang.String from)
public void setReplyTo(java.lang.String addresses)
addresses
- reply addresses as comma separated string, may be null.public void setSubject(java.lang.String subject)
public void setBufferSize(int bufferSize)
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 setSMTPHost(java.lang.String smtpHost)
public java.lang.String getSMTPHost()
public void setTo(java.lang.String to)
public int getBufferSize()
public void setEvaluatorClass(java.lang.String value)
TriggeringEventEvaluator
interface. A corresponding object will
be instantiated and assigned as the triggering event evaluator
for the SMTPAppender.public void setLocationInfo(boolean locationInfo)
Location information extraction is comparatively very slow and should be avoided unless performance is not a concern.
public boolean getLocationInfo()
public void setCc(java.lang.String addresses)
addresses
- recipient addresses as comma separated string, may be null.public java.lang.String getCc()
public void setBcc(java.lang.String addresses)
addresses
- recipient addresses as comma separated string, may be null.public java.lang.String getBcc()
public void setSMTPPassword(java.lang.String password)
password
- password, may be null.public void setSMTPUsername(java.lang.String username)
username
- user name, may be null.public void setSMTPDebug(boolean debug)
debug
- debug flag.public java.lang.String getSMTPPassword()
public java.lang.String getSMTPUsername()
public boolean getSMTPDebug()
public final void setEvaluator(TriggeringEventEvaluator trigger)
trigger
- triggering event evaluator.public final TriggeringEventEvaluator getEvaluator()
public boolean parseUnrecognizedElement(org.w3c.dom.Element element, java.util.Properties props) throws java.lang.Exception
parseUnrecognizedElement
在接口中 UnrecognizedElementHandler
element
- element, may not be null.props
- properties in force, may be null.java.lang.Exception
- throw an exception to prevent activation
of the configured object.public final java.lang.String getSMTPProtocol()
public final void setSMTPProtocol(java.lang.String val)
val
- transport protocol, may be null.public final int getSMTPPort()
public final void setSMTPPort(int val)
val
- port, negative values indicate use of default ports for protocol.public final boolean getSendOnClose()
public final void setSendOnClose(boolean val)
val
- if true all buffered logging events will be sent when appender is closed.