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
public abstract class SMTPAppenderBase<E> extends AppenderBase<E>
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.- Author:
- Ceki Gülcü, Sébastien Pennec
-
-
Field Summary
Fields Modifier and Type Field Description protected CyclicBufferTracker<E>cbTrackerprotected Discriminator<E>discriminatorprotected EventEvaluator<E>eventEvaluatorprotected Layout<E>layoutprotected javax.mail.Sessionsessionprotected Layout<E>subjectLayout-
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 Constructor Description SMTPAppenderBase()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddTo(java.lang.String to)protected voidappend(E eventObject)Perform SMTPAppender specific appending actions, delegating some of them to a subclass and checking if the event triggers an e-mail to be sent.booleancheckEntryConditions()This method determines if there is a sense in attempting to append.protected abstract booleaneventMarksEndOfLife(E eventObject)protected abstract voidfillBuffer(CyclicBuffer<E> cb, java.lang.StringBuffer sbuf)java.lang.StringgetCharsetEncoding()CyclicBufferTracker<E>getCyclicBufferTracker()Discriminator<E>getDiscriminator()java.lang.StringgetFrom()Returns value of the From option.java.lang.StringgetJndiLocation()Layout<E>getLayout()java.lang.StringgetLocalhost()java.lang.StringgetPassword()java.lang.StringgetSmtpHost()Returns value of the SMTPHost option.java.lang.StringgetSMTPHost()Alias for getSmtpHost().intgetSmtpPort()SeesetSmtpPort(int)intgetSMTPPort()Alias forgetSmtpPort()java.lang.StringgetSubject()Returns value of the Subject option.java.util.List<java.lang.String>getToAsListOfString()java.util.List<PatternLayoutBase<E>>getToList()Returns value of the toList option.java.lang.StringgetUsername()booleanisAsynchronousSending()booleanisSessionViaJNDI()booleanisSSL()booleanisSTARTTLS()protected abstract PatternLayoutBase<E>makeNewToPatternLayout(java.lang.String toPattern)protected abstract Layout<E>makeSubjectLayout(java.lang.String subjectStr)return a layout for the subject string as appropriate for the module.protected voidsendBuffer(CyclicBuffer<E> cb, E lastEventObject)Send the contents of the cyclic buffer as an e-mail message.voidsetAsynchronousSending(boolean asynchronousSending)By default, SMTAppender transmits emails asynchronously.voidsetCharsetEncoding(java.lang.String charsetEncoding)Set the character set encoding of the outgoing email messages.voidsetCyclicBufferTracker(CyclicBufferTracker<E> cbTracker)voidsetDiscriminator(Discriminator<E> discriminator)voidsetEvaluator(EventEvaluator<E> eventEvaluator)The EventEvaluator option takes a string value representing the name of the class implementing theEventEvaluatorinterface.voidsetFrom(java.lang.String from)The From option takes a string value which should be a e-mail address of the sender.voidsetJndiLocation(java.lang.String jndiLocation)Set the location where aSessionresource is located in JNDI.voidsetLayout(Layout<E> layout)voidsetLocalhost(java.lang.String localhost)Set the "mail.smtp.localhost" property to the value passed as parameter to this method.voidsetPassword(java.lang.String password)voidsetSessionViaJNDI(boolean sessionViaJNDI)If set to true, aSessionresource will be retrieved from JNDI.voidsetSmtpHost(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.voidsetSMTPHost(java.lang.String smtpHost)Alias for smtpHostvoidsetSmtpPort(int port)The port where the SMTP server is running.voidsetSMTPPort(int port)Alias forsetSmtpPort(int).voidsetSSL(boolean ssl)voidsetSTARTTLS(boolean startTLS)voidsetSubject(java.lang.String subject)The Subject option takes a string value which should be a the subject of the e-mail message.voidsetUsername(java.lang.String username)voidstart()Start the appendervoidstop()protected abstract voidsubAppend(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 Detail
-
session
protected javax.mail.Session session
-
eventEvaluator
protected EventEvaluator<E> eventEvaluator
-
discriminator
protected Discriminator<E> discriminator
-
cbTracker
protected CyclicBufferTracker<E> cbTracker
-
-
Method Detail
-
makeSubjectLayout
protected abstract Layout<E> makeSubjectLayout(java.lang.String subjectStr)
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:
startin interfaceLifeCycle- Overrides:
startin classAppenderBase<E>
-
append
protected void append(E eventObject)
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:
appendin classAppenderBase<E>
-
eventMarksEndOfLife
protected abstract boolean eventMarksEndOfLife(E eventObject)
-
subAppend
protected abstract void subAppend(CyclicBuffer<E> cb, E eventObject)
-
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 valuefalseis returned.
-
stop
public void stop()
- Specified by:
stopin interfaceLifeCycle- Overrides:
stopin classAppenderBase<E>
-
getToList
public java.util.List<PatternLayoutBase<E>> getToList()
Returns value of the toList option.
-
sendBuffer
protected void sendBuffer(CyclicBuffer<E> cb, E lastEventObject)
Send the contents of the cyclic buffer as an e-mail message.
-
fillBuffer
protected abstract void fillBuffer(CyclicBuffer<E> cb, java.lang.StringBuffer sbuf)
-
getFrom
public java.lang.String getFrom()
Returns value of the From option.
-
getSubject
public java.lang.String getSubject()
Returns value of the Subject option.
-
setFrom
public void setFrom(java.lang.String from)
The From option takes a string value which should be a e-mail address of the sender.
-
setSubject
public void setSubject(java.lang.String subject)
The Subject option takes a string value which should be a the subject of the e-mail message.
-
setSMTPHost
public void setSMTPHost(java.lang.String smtpHost)
Alias for smtpHost- Parameters:
smtpHost-
-
setSmtpHost
public 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.
-
getSMTPHost
public java.lang.String getSMTPHost()
Alias for getSmtpHost().
-
getSmtpHost
public java.lang.String 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
public java.lang.String getLocalhost()
-
setLocalhost
public void setLocalhost(java.lang.String localhost)
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
public CyclicBufferTracker<E> getCyclicBufferTracker()
-
setCyclicBufferTracker
public void setCyclicBufferTracker(CyclicBufferTracker<E> cbTracker)
-
getDiscriminator
public Discriminator<E> getDiscriminator()
-
setDiscriminator
public void setDiscriminator(Discriminator<E> discriminator)
-
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
public void addTo(java.lang.String to)
-
makeNewToPatternLayout
protected abstract PatternLayoutBase<E> makeNewToPatternLayout(java.lang.String toPattern)
-
getToAsListOfString
public java.util.List<java.lang.String> getToAsListOfString()
-
isSTARTTLS
public boolean isSTARTTLS()
-
setSTARTTLS
public void setSTARTTLS(boolean startTLS)
-
isSSL
public boolean isSSL()
-
setSSL
public void setSSL(boolean ssl)
-
setEvaluator
public void setEvaluator(EventEvaluator<E> eventEvaluator)
The EventEvaluator option takes a string value representing the name of the class implementing theEventEvaluatorinterface. A corresponding object will be instantiated and assigned as the event evaluator for the SMTPAppender.
-
getUsername
public java.lang.String getUsername()
-
setUsername
public void setUsername(java.lang.String username)
-
getPassword
public java.lang.String getPassword()
-
setPassword
public void setPassword(java.lang.String password)
-
getCharsetEncoding
public java.lang.String getCharsetEncoding()
- Returns:
- the charset encoding value
- See Also:
setCharsetEncoding(String)
-
getJndiLocation
public java.lang.String getJndiLocation()
-
setJndiLocation
public void setJndiLocation(java.lang.String jndiLocation)
Set the location where aSessionresource 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, aSessionresource will be retrieved from JNDI. Default is false.- Parameters:
sessionViaJNDI- whether to obtain a javax.mail.Session by JNDI- Since:
- 1.0.6
-
setCharsetEncoding
public void setCharsetEncoding(java.lang.String charsetEncoding)
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-
-
-