Apache Log4cxx  Version 2.0.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::spi::OptionHandler log4cxx::helpers::Object

Public Member Functions

 SMTPAppender ()
 The default constructor will instantiate the appender with a spi::TriggeringEventEvaluator that will trigger on events with level ERROR or higher.
 SMTPAppender (const 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
 Override this method to set option to value.
void activateOptions () override
 Activate the options that were previously set with calls to option setters.
void append (const spi::LoggingEventPtr &event) 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.
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.
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 newValue)
 use newValue, an integer in the range 1 to 10 million, as 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 (const 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.
void activateOptions (helpers::Pool &)
Public Member Functions inherited from log4cxx::AppenderSkeleton
 AppenderSkeleton (const LayoutPtr &layout={})
virtual ~AppenderSkeleton ()
void addFilter (const spi::FilterPtr &newFilter) override
 Add newFilter to end of the spi::Filter chain.
void clearFilters () override
 Clear the spi::Filter chain.
void close () override
 Release any resources allocated within the appender such as file handles, network connections, etc.
const spi::ErrorHandlerPtr getErrorHandler () const
 The currently set spi::ErrorHandler for this Appender.
spi::FilterPtr getFilter () const override
 The first spi::Filter in the filter chain for this Appender.
const spi::FilterPtr getFirstFilter () const
 The first spi::Filter in the filter chain for this Appender.
LayoutPtr getLayout () const override
 The currently set Layout for this appender.
LogString getName () const override
 The name of this Appender.
const LevelPtr getThreshold () const
 This appender's current threshold level.
bool isAsSevereAsThreshold (const LevelPtr &level) const
 Is level greater than or equal to this appender's threshold?
void doAppend (const spi::LoggingEventPtr &event) override
 Call doAppendImpl after acquiring a lock that prevents other threads from concurrently executing doAppendImpl.
void setErrorHandler (const spi::ErrorHandlerPtr &newValue)
 Use newValue as the spi::ErrorHandler for this Appender.
void setLayout (const LayoutPtr &newValue) override
 Use newValue as the layout for this appender.
void setName (const LogString &newValue) override
 Use newValue for the name of this Appender.
void setThreshold (const LevelPtr &newValue)
 Use newValue as this appender's threshold level.
void activateOptions (helpers::Pool &)
Public Member Functions inherited from log4cxx::Appender
virtual ~Appender ()
void doAppend (const spi::LoggingEventPtr &event, helpers::Pool &pool)
virtual bool requiresLayout () const
Public Member Functions inherited from log4cxx::spi::OptionHandler
virtual ~OptionHandler ()
void activateOptions (helpers::Pool &)
Public Member Functions inherited from log4cxx::helpers::Object
virtual ~Object ()
virtual const helpers::Class & getClass () const =0
virtual bool instanceof (const Class &clazz) const =0
virtual const void * cast (const Class &clazz) const =0

Static Public Attributes

static const int MaxBufferedEventCount = 10000000

Additional Inherited Members

Protected Member Functions inherited from log4cxx::AppenderSkeleton
 AppenderSkeleton (LOG4CXX_PRIVATE_PTR(AppenderSkeletonPrivate) priv)
void doAppendImpl (const spi::LoggingEventPtr &event)
 Call the AppenderSkeleton::append method if the level of event is not lower than this appender's threshold and no attached spi::Filter indicates event is rejected.
bool isAccepted (const spi::LoggingEventPtr &event) const
 Does no attached filter deny event or does an attached filter accept event?

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="${PROGRAM_FILE_PATH.PARENT_PATH}/${PROGRAM_FILE_PATH.STEM}.log" />
    <layout class="PatternLayout">
    <param name="ConversionPattern" value="%d %-5p %c{2} - %m%n"/>
    </layout>
    </appender>
    <appender name="SENDMAIL" class="SMTPAppender">
    <param name="from" value="${PROGRAM_FILE_PATH.STEM}@example.org" />
    <param name="to" value="some_support_group@example.org" />
    <param name="subject" value="Service error detected in ${PROGRAM_FILE_PATH.STEM}" />
    <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/2]

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

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

◆ SMTPAppender() [2/2]

log4cxx::net::SMTPAppender::SMTPAppender ( const 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() [1/2]

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

◆ activateOptions() [2/2]

Deprecated
This function is deprecated and will be removed in a future version.
Deprecated
Use activateOptions() without parameters instead

◆ append()

void log4cxx::net::SMTPAppender::append ( const spi::LoggingEventPtr & event)
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.

◆ 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.

◆ 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 newValue)

use newValue, an integer in the range 1 to 10 million, as the maximum number of logging events to collect in a cyclic buffer.

When the newValue 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 ( const 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

Override this method to 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} -
buffersize 1..10000000 512
evaluatorClass (2) -
allowPlainTextAuthentication True,False False

(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.

Member Data Documentation

◆ MaxBufferedEventCount

const int log4cxx::net::SMTPAppender::MaxBufferedEventCount = 10000000
static

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