Apache Log4cxx  Version 1.3.0
Loading...
Searching...
No Matches
log4cxx::net::SMTPAppender Class Reference

Send an e-mail when a specific logging event occurs, typically when an ERROR level logging event is sent to the appender. More...

#include <smtpappender.h>

Inheritance diagram for log4cxx::net::SMTPAppender:
log4cxx::AppenderSkeleton log4cxx::Appender log4cxx::helpers::Object log4cxx::spi::OptionHandler log4cxx::helpers::Object

Public Member Functions

 SMTPAppender ()
 
 SMTPAppender (log4cxx::helpers::Pool &p)
 The default constructor will instantiate the appender with a spi::TriggeringEventEvaluator that will trigger on events with level ERROR or higher.
 
 SMTPAppender (spi::TriggeringEventEvaluatorPtr evaluator)
 Use evaluator passed as parameter as the spi::TriggeringEventEvaluator for this net::SMTPAppender.
 
 ~SMTPAppender ()
 
void setOption (const LogString &option, const LogString &value) override
 Set option to value.
 
void activateOptions (helpers::Pool &p) override
 Activate the options that were previously set with calls to option setters.
 
void append (const spi::LoggingEventPtr &event, helpers::Pool &p) override
 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.
 
void close () override
 Release any resources allocated within the appender such as file handles, network connections, etc.
 
LogString getTo () const
 Returns value of the To option.
 
LogString getCc () const
 Returns value of the cc option.
 
LogString getBcc () const
 Returns value of the bcc option.
 
bool requiresLayout () const override
 The SMTPAppender requires a Layout.
 
void sendBuffer (log4cxx::helpers::Pool &p)
 Send the contents of the cyclic buffer as an e-mail message.
 
LogString getEvaluatorClass ()
 Returns value of the EvaluatorClass option.
 
LogString getFrom () const
 Returns value of the From option.
 
LogString getSubject () const
 Returns value of the Subject option.
 
void setFrom (const LogString &from)
 The From option takes a string value which should be a e-mail address of the sender.
 
void setSubject (const LogString &subject)
 The Subject option takes a string value which should be a the subject of the e-mail message.
 
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 setSMTPHost (const LogString &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.
 
LogString getSMTPHost () const
 Returns value of the SMTPHost option.
 
void setSMTPPort (int port)
 The SMTPPort option takes a string value which should be a the port of the SMTP server that will send the e-mail message.
 
int getSMTPPort () const
 Returns value of the SMTPHost option.
 
void setTo (const LogString &to)
 The To option takes a string value which should be a comma separated list of e-mail address of the recipients.
 
void setCc (const LogString &to)
 The Cc option takes a string value which should be a comma separated list of e-mail address of the cc'd recipients.
 
void setBcc (const LogString &to)
 The Bcc option takes a string value which should be a comma separated list of e-mail address of the bcc'd recipients.
 
void setSMTPUsername (const LogString &newVal)
 The SMTPUsername option takes a string value which should be a the user name for the SMTP server.
 
LogString getSMTPUsername () const
 Returns value of the SMTPUsername option.
 
void setSMTPPassword (const LogString &newVal)
 The SMTPPassword option takes a string value which should be a the password for the SMTP server.
 
LogString getSMTPPassword () const
 Returns value of the SMTPPassword option.
 
int getBufferSize () const
 Returns value of the BufferSize option.
 
log4cxx::spi::TriggeringEventEvaluatorPtr getEvaluator () const
 Gets the current triggering evaluator.
 
void setEvaluator (log4cxx::spi::TriggeringEventEvaluatorPtr &trigger)
 Sets the triggering evaluator.
 
void setEvaluatorClass (const LogString &value)
 The EvaluatorClass option takes a string value representing the name of the class implementing the spi::TriggeringEventEvaluator interface.
 
void setLocationInfo (bool locationInfo)
 The LocationInfo option is provided for compatibility with log4j and has no effect in log4cxx.
 
bool getLocationInfo () const
 Returns value of the LocationInfo option.
 
- Public Member Functions inherited from log4cxx::AppenderSkeleton
 AppenderSkeleton ()
 
 AppenderSkeleton (const LayoutPtr &layout)
 
virtual ~AppenderSkeleton ()
 
void finalize ()
 Finalize this appender by calling the derived class' close method.
 
void activateOptions (helpers::Pool &) override
 Activate the options that were previously set with calls to option setters.
 
void setOption (const LogString &option, const LogString &value) override
 Set option to value.
 
void addFilter (const spi::FilterPtr newFilter) override
 Add a filter to end of the filter list.
 
void clearFilters () override
 Clear the filters chain.
 
const spi::ErrorHandlerPtr getErrorHandler () const
 Return the currently set spi::ErrorHandler for this Appender.
 
spi::FilterPtr getFilter () const override
 Returns the head Filter.
 
const spi::FilterPtr getFirstFilter () const
 Return the first filter in the filter chain for this Appender.
 
LayoutPtr getLayout () const override
 Returns the layout of this appender.
 
LogString getName () const override
 Returns the name of this Appender.
 
const LevelPtr getThreshold () const
 Returns this appenders threshold level.
 
bool isAsSevereAsThreshold (const LevelPtr &level) const
 Check whether the message level is below the appender's threshold.
 
void doAppend (const spi::LoggingEventPtr &event, helpers::Pool &pool) override
 This method performs threshold checks and invokes filters before delegating actual logging to the subclasses specific AppenderSkeleton::append method.
 
void setErrorHandler (const spi::ErrorHandlerPtr eh)
 Set the ErrorHandler for this Appender.
 
void setLayout (const LayoutPtr layout1) override
 Set the layout for this appender.
 
void setName (const LogString &name1) override
 Set the name of this Appender.
 
void setThreshold (const LevelPtr &threshold)
 Set the threshold level.
 
- Public Member Functions inherited from log4cxx::Appender
virtual ~Appender ()
 
virtual void addFilter (const spi::FilterPtr newFilter)=0
 Add a filter to the end of the filter list.
 
virtual spi::FilterPtr getFilter () const =0
 Returns the head Filter.
 
virtual void clearFilters ()=0
 Clear the list of filters by removing all the filters in it.
 
virtual void close ()=0
 Release any resources allocated within the appender such as file handles, network connections, etc.
 
virtual void doAppend (const spi::LoggingEventPtr &event, log4cxx::helpers::Pool &pool)=0
 Log in Appender specific way.
 
virtual LogString getName () const =0
 Get the name of this appender.
 
virtual void setLayout (const LayoutPtr layout)=0
 Set the Layout for this appender.
 
virtual LayoutPtr getLayout () const =0
 Returns this appenders layout.
 
virtual void setName (const LogString &name)=0
 Set the name of this appender.
 
virtual bool requiresLayout () const =0
 Configurators call this method to determine if the appender requires a layout.
 
- Public Member Functions inherited from log4cxx::spi::OptionHandler
virtual ~OptionHandler ()
 
virtual void activateOptions (helpers::Pool &p)=0
 Activate the options that were previously set with calls to option setters.
 
virtual void setOption (const LogString &option, const LogString &value)=0
 Set option to value.
 
- Public Member Functions inherited from log4cxx::helpers::Object
virtual ~Object ()
 
virtual const helpers::ClassgetClass () const =0
 
virtual bool instanceof (const Class &clazz) const =0
 
virtual const void * cast (const Class &clazz) const =0
 

Additional Inherited Members

- Protected Member Functions inherited from log4cxx::AppenderSkeleton
 AppenderSkeleton (LOG4CXX_PRIVATE_PTR(AppenderSkeletonPrivate) priv)
 
virtual void append (const spi::LoggingEventPtr &event, log4cxx::helpers::Pool &p)=0
 Subclasses of AppenderSkeleton should implement this method to perform actual logging.
 
void doAppendImpl (const spi::LoggingEventPtr &event, log4cxx::helpers::Pool &pool)
 

Detailed Description

Send an e-mail when a specific logging event occurs, typically when an ERROR level logging event is sent to the appender.

A value must be provided for the following param elements :

  • smtpHost - The URL or IP address of the SMTP server.
  • from - The email address in the from field of the message.
  • one of to, cc, bcc - An email address in the message.

The following param elements are optional:

  • smtpPort - The TCP/IP port number on the SMTP server. By default port 25 is assumed.
  • subject - Content for the the subject field of the message.
  • smtpUsername - Provided when the SMTP server requests authentication.
  • smtpPassword - Provided when the SMTP server requests authentication.
  • BufferSize - The number of logging events delivered in an e-mail. 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 512 logging events are kept in its cyclic buffer.
  • evaluatorClass - The registered spi::TriggeringEventEvaluator sub-class that provides the isTriggeringEvent implementation. This attribute can also be set using the triggeringPolicy element. By default an email is sent when the level of the logging event is greater or equal to ERROR.

    An example configuration is:

    <?xml version="1.0" encoding="UTF-8" ?>
    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    <appender name="A1" class="RollingFileAppender">
    <param name="File" value="${TEMP}/SomeApplicationName.log" />
    <param name="Append" value="true" />
    <layout class="PatternLayout">
    <param name="ConversionPattern" value="%d %-5p %c{2} - %m%n"/>
    </layout>
    </appender>
    <appender name="SENDMAIL" class="SMTPAppender">
    <param name="from" value="service_name@example.org" />
    <param name="to" value="some_support_group@example.org" />
    <param name="subject" value="Service error detected" />
    <param name="SMTPHost" value="smtp.example.com"/>
    <layout class="PatternLayout">
    <param name="ConversionPattern" value="%-5p %c{2} - %m%n"/>
    </layout>
    <!-- triggeringPolicy class="SpecialTriggeringEventEvaluator" -->
    <!-- param name="evaluatorClass" value="SpecialTriggeringEventEvaluator" -->
    </appender>
    <appender name="ASYNC" class="AsyncAppender">
    <param name="BufferSize" value="1000"/>
    <param name="Blocking" value="false"/>
    <appender-ref ref="SENDMAIL"/>
    </appender>
    <root>
    <priority value ="INFO" />
    <appender-ref ref="A1" />
    <appender-ref ref="ASYNC" />
    </root>
    </log4j:configuration>

Constructor & Destructor Documentation

◆ SMTPAppender() [1/3]

log4cxx::net::SMTPAppender::SMTPAppender ( )

◆ SMTPAppender() [2/3]

log4cxx::net::SMTPAppender::SMTPAppender ( log4cxx::helpers::Pool p)

The default constructor will instantiate the appender with a spi::TriggeringEventEvaluator that will trigger on events with level ERROR or higher.

◆ SMTPAppender() [3/3]

log4cxx::net::SMTPAppender::SMTPAppender ( spi::TriggeringEventEvaluatorPtr  evaluator)

Use evaluator passed as parameter as the spi::TriggeringEventEvaluator for this net::SMTPAppender.

◆ ~SMTPAppender()

log4cxx::net::SMTPAppender::~SMTPAppender ( )

Member Function Documentation

◆ activateOptions()

void log4cxx::net::SMTPAppender::activateOptions ( helpers::Pool p)
overridevirtual

Activate the options that were previously set with calls to option setters.

Will not activate and will log an error message if:

  • no layout is provided
  • no TriggeringEventEvaluator is provided
  • any required field is missing
  • a non-ascii character is detected where not permitted

.

Reimplemented from log4cxx::AppenderSkeleton.

◆ append()

void log4cxx::net::SMTPAppender::append ( const spi::LoggingEventPtr event,
helpers::Pool p 
)
overridevirtual

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.

Implements log4cxx::AppenderSkeleton.

◆ close()

void log4cxx::net::SMTPAppender::close ( )
overridevirtual

Release any resources allocated within the appender such as file handles, network connections, etc.

It is a programming error to append to a closed appender.

Implements log4cxx::Appender.

◆ getBcc()

LogString log4cxx::net::SMTPAppender::getBcc ( ) const

Returns value of the bcc option.

◆ getBufferSize()

int log4cxx::net::SMTPAppender::getBufferSize ( ) const

Returns value of the BufferSize option.

◆ getCc()

LogString log4cxx::net::SMTPAppender::getCc ( ) const

Returns value of the cc option.

◆ getEvaluator()

log4cxx::spi::TriggeringEventEvaluatorPtr log4cxx::net::SMTPAppender::getEvaluator ( ) const

Gets the current triggering evaluator.

Returns
triggering evaluator.

◆ getEvaluatorClass()

LogString log4cxx::net::SMTPAppender::getEvaluatorClass ( )

Returns value of the EvaluatorClass option.

◆ getFrom()

LogString log4cxx::net::SMTPAppender::getFrom ( ) const

Returns value of the From option.

◆ getLocationInfo()

bool log4cxx::net::SMTPAppender::getLocationInfo ( ) const

Returns value of the LocationInfo option.

◆ getSMTPHost()

LogString log4cxx::net::SMTPAppender::getSMTPHost ( ) const

Returns value of the SMTPHost option.

◆ getSMTPPassword()

LogString log4cxx::net::SMTPAppender::getSMTPPassword ( ) const

Returns value of the SMTPPassword option.

◆ getSMTPPort()

int log4cxx::net::SMTPAppender::getSMTPPort ( ) const

Returns value of the SMTPHost option.

◆ getSMTPUsername()

LogString log4cxx::net::SMTPAppender::getSMTPUsername ( ) const

Returns value of the SMTPUsername option.

◆ getSubject()

LogString log4cxx::net::SMTPAppender::getSubject ( ) const

Returns value of the Subject option.

◆ getTo()

LogString log4cxx::net::SMTPAppender::getTo ( ) const

Returns value of the To option.

◆ requiresLayout()

bool log4cxx::net::SMTPAppender::requiresLayout ( ) const
overridevirtual

The SMTPAppender requires a Layout.

Implements log4cxx::Appender.

◆ sendBuffer()

void log4cxx::net::SMTPAppender::sendBuffer ( log4cxx::helpers::Pool p)

Send the contents of the cyclic buffer as an e-mail message.

◆ setBcc()

void log4cxx::net::SMTPAppender::setBcc ( const LogString to)

The Bcc option takes a string value which should be a comma separated list of e-mail address of the bcc'd recipients.

◆ setBufferSize()

void log4cxx::net::SMTPAppender::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.

◆ setCc()

void log4cxx::net::SMTPAppender::setCc ( const LogString to)

The Cc option takes a string value which should be a comma separated list of e-mail address of the cc'd recipients.

◆ setEvaluator()

void log4cxx::net::SMTPAppender::setEvaluator ( log4cxx::spi::TriggeringEventEvaluatorPtr &  trigger)

Sets the triggering evaluator.

Parameters
triggertriggering evaluator.

◆ setEvaluatorClass()

void log4cxx::net::SMTPAppender::setEvaluatorClass ( const LogString value)

The EvaluatorClass option takes a string value representing the name of the class implementing the spi::TriggeringEventEvaluator interface.

A corresponding object will be instantiated and assigned as the triggering event evaluator for the SMTPAppender.

◆ setFrom()

void log4cxx::net::SMTPAppender::setFrom ( const LogString from)

The From option takes a string value which should be a e-mail address of the sender.

◆ setLocationInfo()

void log4cxx::net::SMTPAppender::setLocationInfo ( bool  locationInfo)

The LocationInfo option is provided for compatibility with log4j and has no effect in log4cxx.

◆ setOption()

void log4cxx::net::SMTPAppender::setOption ( const LogString option,
const LogString value 
)
overridevirtual

Set option to value.

Supported options Supported values Default value
smtpHost {any} -
smtpPort {int} 25
smtpUserName {any} -
smtpPassword {any} -
from (1) -
to (1) -
cc (1) -
bcc (1) -
subject {any} -
subject {any} -
buffersize {int} 512
evaluatorClass (2) -

(1) Only ASCII charaters

(2) A registered class deriving from TriggeringEventEvaluator

See also
AppenderSkeleton::setOption()

Reimplemented from log4cxx::AppenderSkeleton.

◆ setSMTPHost()

void log4cxx::net::SMTPAppender::setSMTPHost ( const LogString 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.

◆ setSMTPPassword()

void log4cxx::net::SMTPAppender::setSMTPPassword ( const LogString newVal)

The SMTPPassword option takes a string value which should be a the password for the SMTP server.

◆ setSMTPPort()

void log4cxx::net::SMTPAppender::setSMTPPort ( int  port)

The SMTPPort option takes a string value which should be a the port of the SMTP server that will send the e-mail message.

◆ setSMTPUsername()

void log4cxx::net::SMTPAppender::setSMTPUsername ( const LogString newVal)

The SMTPUsername option takes a string value which should be a the user name for the SMTP server.

◆ setSubject()

void log4cxx::net::SMTPAppender::setSubject ( const LogString subject)

The Subject option takes a string value which should be a the subject of the e-mail message.

◆ setTo()

void log4cxx::net::SMTPAppender::setTo ( const LogString to)

The To option takes a string value which should be a comma separated list of e-mail address of the recipients.


The documentation for this class was generated from the following file: