ch.qos.logback.core.net
Class SMTPAppenderBase<E>

java.lang.Object
  extended by ch.qos.logback.core.spi.ContextAwareBase
      extended by ch.qos.logback.core.AppenderBase<E>
          extended by ch.qos.logback.core.net.SMTPAppenderBase<E>
All Implemented Interfaces:
Appender<E>, ContextAware, FilterAttachable<E>, LifeCycle

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
protected  CyclicBufferTracker<E> cbTracker
           
protected  Discriminator<E> discriminator
           
protected  EventEvaluator<E> eventEvaluator
           
protected  Layout<E> layout
           
protected  javax.mail.internet.MimeMessage mimeMsg
           
protected  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
SMTPAppenderBase()
           
 
Method Summary
 void addTo(String to)
           
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.
 boolean checkEntryConditions()
          This method determines if there is a sense in attempting to append.
protected abstract  void fillBuffer(CyclicBuffer<E> cb, StringBuffer sbuf)
           
 String getCharsetEncoding()
           
 CyclicBufferTracker<E> getCyclicBufferTracker()
           
 Discriminator<E> getDiscriminator()
           
 String getFrom()
          Returns value of the From option.
 Layout<E> getLayout()
           
 String getLocalhost()
           
 javax.mail.Message getMessage()
           
 String getPassword()
           
 String getSmtpHost()
          Returns value of the SMTPHost option.
 String getSMTPHost()
          Alias for getSmtpHost().
 int getSmtpPort()
          See setSmtpPort(int)
 int getSMTPPort()
          Alias for getSmtpPort()
 String getSubject()
          Returns value of the Subject option.
 List<String> getToAsListOfString()
           
 List<PatternLayoutBase<E>> getToList()
          Returns value of the toList option.
 String getUsername()
           
protected abstract  boolean isEventMarkedForBufferRemoval(E eventObject)
           
 boolean isSSL()
           
 boolean isSTARTTLS()
           
protected abstract  PatternLayoutBase<E> makeNewToPatternLayout(String toPattern)
           
protected abstract  Layout<E> makeSubjectLayout(String subjectStr)
          return a layout for the subject string as appropriate for the module.
protected  void sendBuffer(CyclicBuffer<E> cb, E lastEventObject)
          Send the contents of the cyclic buffer as an e-mail message.
 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 the EventEvaluator interface.
 void setFrom(String from)
          The From option takes a string value which should be a e-mail address of the sender.
 void setLayout(Layout<E> layout)
           
 void setLocalhost(String localhost)
          Set the "mail.smtp.localhost" property to the value passed as parameter to this method.
 void setMessage(javax.mail.internet.MimeMessage msg)
           
 void setPassword(String password)
           
 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 smtpHost
 void setSmtpPort(int port)
          The port where the SMTP server is running.
 void setSMTPPort(int port)
          Alias for setSmtpPort(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 appender
 void 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 Detail

subjectLayout

protected Layout<E> subjectLayout

layout

protected Layout<E> layout

mimeMsg

protected javax.mail.internet.MimeMessage mimeMsg

eventEvaluator

protected EventEvaluator<E> eventEvaluator

discriminator

protected Discriminator<E> discriminator

cbTracker

protected CyclicBufferTracker<E> cbTracker
Constructor Detail

SMTPAppenderBase

public SMTPAppenderBase()
Method Detail

makeSubjectLayout

protected abstract Layout<E> makeSubjectLayout(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:
start in interface LifeCycle
Overrides:
start in class AppenderBase<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:
append in class AppenderBase<E>

isEventMarkedForBufferRemoval

protected abstract boolean isEventMarkedForBufferRemoval(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 value false is returned.


stop

public void stop()
Specified by:
stop in interface LifeCycle
Overrides:
stop in class AppenderBase<E>

getToList

public 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,
                                   StringBuffer sbuf)

getFrom

public String getFrom()
Returns value of the From option.


getSubject

public String getSubject()
Returns value of the Subject option.


setFrom

public void setFrom(String from)
The From option takes a string value which should be a e-mail address of the sender.


setSubject

public void setSubject(String subject)
The Subject option takes a string value which should be a the subject of the e-mail message.


setSMTPHost

public void setSMTPHost(String smtpHost)
Alias for smtpHost

Parameters:
smtpHost -

setSmtpHost

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.


getSMTPHost

public String getSMTPHost()
Alias for getSmtpHost().


getSmtpHost

public String getSmtpHost()
Returns value of the SMTPHost option.


setSMTPPort

public void setSMTPPort(int port)
Alias for setSmtpPort(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 for getSmtpPort()

Returns:

getSmtpPort

public int getSmtpPort()
See setSmtpPort(int)

Returns:

getLocalhost

public String getLocalhost()

setLocalhost

public void setLocalhost(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)

addTo

public void addTo(String to)

makeNewToPatternLayout

protected abstract PatternLayoutBase<E> makeNewToPatternLayout(String toPattern)

getToAsListOfString

public List<String> getToAsListOfString()

getMessage

public javax.mail.Message getMessage()

setMessage

public void setMessage(javax.mail.internet.MimeMessage msg)

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 the EventEvaluator interface. A corresponding object will be instantiated and assigned as the event evaluator for the SMTPAppender.


getUsername

public String getUsername()

setUsername

public void setUsername(String username)

getPassword

public String getPassword()

setPassword

public void setPassword(String password)

getCharsetEncoding

public String getCharsetEncoding()
Returns:
the charset encoding value
See Also:
setCharsetEncoding(String)

setCharsetEncoding

public void setCharsetEncoding(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 -

getLayout

public Layout<E> getLayout()

setLayout

public void setLayout(Layout<E> layout)


Copyright © 2005-2012 QOS.ch. All Rights Reserved.