Package ch.qos.logback.core.net
Class SMTPAppenderBase<E>
java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
ch.qos.logback.core.AppenderBase<E>
ch.qos.logback.core.net.SMTPAppenderBase<E>
- All Implemented Interfaces:
Appender<E>
,ContextAware
,FilterAttachable<E>
,LifeCycle
- Direct Known Subclasses:
SMTPAppender
,SMTPAppender
An abstract class that provides support for sending events to an email
address.
See http://logback.qos.ch/manual/appenders.html#SMTPAppender for further
documentation.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescription(package private) boolean
protected CyclicBufferTracker<E>
private String
(package private) long
protected Discriminator<E>
(package private) static javax.mail.internet.InternetAddress[]
private int
protected EventEvaluator<E>
private String
private String
(package private) long
(package private) String
(package private) static final long
(package private) String
protected javax.mail.Session
private boolean
private String
private int
private boolean
private boolean
private String
private List<PatternLayoutBase<E>>
(package private) String
Fields inherited from class ch.qos.logback.core.AppenderBase
name, started
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
protected void
Perform SMTPAppender specific appending actions, delegating some of them to a subclass and checking if the event triggers an e-mail to be sent.private javax.mail.Session
boolean
This method determines if there is a sense in attempting to append.protected abstract boolean
eventMarksEndOfLife
(E eventObject) protected abstract void
fillBuffer
(CyclicBuffer<E> cb, StringBuffer sbuf) (package private) javax.mail.internet.InternetAddress
getAddress
(String addressStr) getFrom()
Returns value of the From option.Returns value of the SMTPHost option.Alias for getSmtpHost().int
SeesetSmtpPort(int)
int
Alias forgetSmtpPort()
Returns value of the Subject option.Returns value of the toList option.boolean
boolean
boolean
isSSL()
boolean
private javax.mail.Session
protected abstract PatternLayoutBase<E>
makeNewToPatternLayout
(String toPattern) makeSubjectLayout
(String subjectStr) return a layout for the subject string as appropriate for the module.private List<javax.mail.internet.InternetAddress>
parseAddress
(E event) protected void
sendBuffer
(CyclicBuffer<E> cb, E lastEventObject) Send the contents of the cyclic buffer as an e-mail message.void
setAsynchronousSending
(boolean asynchronousSending) By default, SMTAppender transmits emails asynchronously.void
setCharsetEncoding
(String charsetEncoding) Set the character set encoding of the outgoing email messages.void
setCyclicBufferTracker
(CyclicBufferTracker<E> cbTracker) void
setDiscriminator
(Discriminator<E> discriminator) void
setEvaluator
(EventEvaluator<E> eventEvaluator) The EventEvaluator option takes a string value representing the name of the class implementing theEventEvaluator
interface.void
The From option takes a string value which should be a e-mail address of the sender.void
setJndiLocation
(String jndiLocation) Set the location where aSession
resource is located in JNDI.void
void
setLocalhost
(String localhost) Set the "mail.smtp.localhost" property to the value passed as parameter to this method.void
setPassword
(String password) void
setSessionViaJNDI
(boolean sessionViaJNDI) If set to true, aSession
resource will be retrieved from JNDI.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.void
setSMTPHost
(String smtpHost) Alias for smtpHostvoid
setSmtpPort
(int port) The port where the SMTP server is running.void
setSMTPPort
(int port) Alias forsetSmtpPort(int)
.void
setSSL
(boolean ssl) void
setSTARTTLS
(boolean startTLS) void
setSubject
(String subject) The Subject option takes a string value which should be a the subject of the e-mail message.void
setUsername
(String username) void
start()
Start the appendervoid
stop()
protected abstract void
subAppend
(CyclicBuffer<E> cb, E eventObject) Methods inherited from class ch.qos.logback.core.AppenderBase
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, toString
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
-
Field Details
-
EMPTY_IA_ARRAY
static javax.mail.internet.InternetAddress[] EMPTY_IA_ARRAY -
MAX_DELAY_BETWEEN_STATUS_MESSAGES
static final long MAX_DELAY_BETWEEN_STATUS_MESSAGES- See Also:
-
lastTrackerStatusPrint
long lastTrackerStatusPrint -
delayBetweenStatusMessages
long delayBetweenStatusMessages -
subjectLayout
-
layout
-
toPatternLayoutList
-
from
-
subjectStr
-
smtpHost
-
smtpPort
private int smtpPort -
starttls
private boolean starttls -
ssl
private boolean ssl -
sessionViaJNDI
private boolean sessionViaJNDI -
jndiLocation
-
username
String username -
password
String password -
localhost
String localhost -
asynchronousSending
boolean asynchronousSending -
charsetEncoding
-
session
protected javax.mail.Session session -
eventEvaluator
-
discriminator
-
cbTracker
-
errorCount
private int errorCount
-
-
Constructor Details
-
SMTPAppenderBase
public SMTPAppenderBase()
-
-
Method Details
-
makeSubjectLayout
return a layout for the subject string as appropriate for the module. If the subjectStr parameter is null, then a default value for subjectStr should be used.- Parameters:
subjectStr
-- Returns:
- a layout as appropriate for the module
-
start
public void start()Start the appender- Specified by:
start
in interfaceLifeCycle
- Overrides:
start
in classAppenderBase<E>
-
lookupSessionInJNDI
private javax.mail.Session lookupSessionInJNDI() -
buildSessionFromProperties
private javax.mail.Session buildSessionFromProperties() -
append
Perform SMTPAppender specific appending actions, delegating some of them to a subclass and checking if the event triggers an e-mail to be sent.- Specified by:
append
in classAppenderBase<E>
-
eventMarksEndOfLife
-
subAppend
-
checkEntryConditions
public 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 valuefalse
is returned. -
stop
public void stop()- Specified by:
stop
in interfaceLifeCycle
- Overrides:
stop
in classAppenderBase<E>
-
getAddress
-
parseAddress
-
getToList
Returns value of the toList option. -
sendBuffer
Send the contents of the cyclic buffer as an e-mail message. -
fillBuffer
-
getFrom
Returns value of the From option. -
getSubject
Returns value of the Subject option. -
setFrom
The From option takes a string value which should be a e-mail address of the sender. -
setSubject
The Subject option takes a string value which should be a the subject of the e-mail message. -
setSMTPHost
Alias for smtpHost- Parameters:
smtpHost
-
-
setSmtpHost
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. -
getSMTPHost
Alias for getSmtpHost(). -
getSmtpHost
Returns value of the SMTPHost option. -
setSMTPPort
public void setSMTPPort(int port) Alias forsetSmtpPort(int)
.- Parameters:
port
-
-
setSmtpPort
public void setSmtpPort(int port) The port where the SMTP server is running. Default value is 25.- Parameters:
port
-
-
getSMTPPort
public int getSMTPPort()Alias forgetSmtpPort()
- Returns:
-
getSmtpPort
public int getSmtpPort()SeesetSmtpPort(int)
- Returns:
-
getLocalhost
-
setLocalhost
Set the "mail.smtp.localhost" property to the value passed as parameter to this method.Useful in case the hostname for the client host is not fully qualified and as a consequence the SMTP server rejects the clients HELO/EHLO command.
- Parameters:
localhost
-
-
getCyclicBufferTracker
-
setCyclicBufferTracker
-
getDiscriminator
-
setDiscriminator
-
isAsynchronousSending
public boolean isAsynchronousSending() -
setAsynchronousSending
public void setAsynchronousSending(boolean asynchronousSending) By default, SMTAppender transmits emails asynchronously. For synchronous email transmission set asynchronousSending to 'false'.- Parameters:
asynchronousSending
- determines whether sending is done asynchronously or not- Since:
- 1.0.4
-
addTo
-
makeNewToPatternLayout
-
getToAsListOfString
-
isSTARTTLS
public boolean isSTARTTLS() -
setSTARTTLS
public void setSTARTTLS(boolean startTLS) -
isSSL
public boolean isSSL() -
setSSL
public void setSSL(boolean ssl) -
setEvaluator
The EventEvaluator option takes a string value representing the name of the class implementing theEventEvaluator
interface. A corresponding object will be instantiated and assigned as the event evaluator for the SMTPAppender. -
getUsername
-
setUsername
-
getPassword
-
setPassword
-
getCharsetEncoding
- Returns:
- the charset encoding value
- See Also:
-
getJndiLocation
-
setJndiLocation
Set the location where aSession
resource is located in JNDI. Default value is "java:comp/env/mail/Session".- Parameters:
jndiLocation
-- Since:
- 1.0.6
-
isSessionViaJNDI
public boolean isSessionViaJNDI() -
setSessionViaJNDI
public void setSessionViaJNDI(boolean sessionViaJNDI) If set to true, aSession
resource will be retrieved from JNDI. Default is false.- Parameters:
sessionViaJNDI
- whether to obtain a javax.mail.Session by JNDI- Since:
- 1.0.6
-
setCharsetEncoding
Set the character set encoding of the outgoing email messages. The default encoding is "UTF-8" which usually works well for most purposes.- Parameters:
charsetEncoding
-
-
getLayout
-
setLayout
-