Apache Log4cxx: log4cxx::WriterAppender Class Reference (original) (raw)

WriterAppender appends log events to a standard output stream. More...

#include <[writerappender.h](writerappender%5F8h%5Fsource.html)>

Public Member Functions
WriterAppender ()
This default constructor does nothing.
~WriterAppender ()
void activateOptions (helpers::Pool &pool) override
Derived appenders should override this method if option structure requires it.
void setImmediateFlush (bool value)
If the ImmediateFlush option is set to true, the appender will flush at the end of each write.
bool getImmediateFlush () const
Returns value of the ImmediateFlush option.
void append (const spi::LoggingEventPtr &event, helpers::Pool &p) override
This method is called by the AppenderSkeleton::doAppend method.
void close () override
Close this appender instance.
LogString getEncoding () const
The current encoding value.
void setEncoding (const LogString &value)
Set the encoding to value.
void setOption (const LogString &option, const LogString &value) override
Set option to value.
void setWriter (const helpers::WriterPtr &writer)
const helpers::WriterPtr getWriter () const
bool requiresLayout () const override
Configurators call this method to determine if the appender requires a layout.
- 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::Class & getClass () const =0
virtual bool instanceof (const Class &clazz) const =0
virtual const void * cast (const Class &clazz) const =0
Protected Member Functions
WriterAppender (const LayoutPtr &layout, helpers::WriterPtr &writer)
WriterAppender (const LayoutPtr &layout)
WriterAppender (std::unique_ptr< WriterAppenderPriv > priv)
virtual bool checkEntryConditions () const
This method determines if there is a sense in attempting to append.
void closeWriter ()
Close the underlying log4cxx::helpers::Writer.
virtual helpers::WriterPtr createWriter (LOG4CXX_16_CONST helpers::OutputStreamPtr &os)
Returns an OutputStreamWriter when passed an OutputStream.
virtual void subAppend (const spi::LoggingEventPtr &event, helpers::Pool &p)
Actual writing occurs here.
virtual void writeFooter (helpers::Pool &p)
Write a footer as produced by the embedded layout's Layout::appendFooter method.
virtual void writeHeader (helpers::Pool &p)
Write a header as produced by the embedded layout's Layout::appendHeader method.
void setWriterInternal (const helpers::WriterPtr &writer)
Set the writer.
- 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)

WriterAppender appends log events to a standard output stream.

log4cxx::WriterAppender::WriterAppender ( )

This default constructor does nothing.

WriterAppender() [2/4]

log4cxx::WriterAppender::WriterAppender ( const LayoutPtr & layout, helpers::WriterPtr & writer ) protected

WriterAppender() [3/4]

log4cxx::WriterAppender::WriterAppender ( const LayoutPtr & layout) protected

WriterAppender() [4/4]

log4cxx::WriterAppender::WriterAppender ( std::unique_ptr< WriterAppenderPriv > priv) protected

~WriterAppender()

log4cxx::WriterAppender::~WriterAppender ( )

activateOptions()

void log4cxx::WriterAppender::activateOptions ( helpers::Pool & pool) overridevirtual

append()

This method is called by the AppenderSkeleton::doAppend method.

If the output stream exists and is writable then write a log statement to the output stream. Otherwise, write a single warning message to stderr.

The format of the output will depend on this appender's layout.

Implements log4cxx::AppenderSkeleton.

checkEntryConditions()

virtual bool log4cxx::WriterAppender::checkEntryConditions ( ) const protectedvirtual

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.

close()

void log4cxx::WriterAppender::close ( ) overridevirtual

Close this appender instance.

The underlying stream or writer is also closed.

Closed appenders cannot be reused.

Implements log4cxx::Appender.

closeWriter()

void log4cxx::WriterAppender::closeWriter ( ) protected

createWriter()

virtual helpers::WriterPtr log4cxx::WriterAppender::createWriter ( LOG4CXX_16_CONST helpers::OutputStreamPtr & os) protectedvirtual

getEncoding()

LogString log4cxx::WriterAppender::getEncoding ( ) const

The current encoding value.

See also

setOption

getImmediateFlush()

bool log4cxx::WriterAppender::getImmediateFlush ( ) const

Returns value of the ImmediateFlush option.

getWriter()

const helpers::WriterPtr log4cxx::WriterAppender::getWriter ( ) const

requiresLayout()

bool log4cxx::WriterAppender::requiresLayout ( ) const overridevirtual

Configurators call this method to determine if the appender requires a layout.

If this method returns true, meaning that layout is required, then the configurator will configure an layout using the configuration information at its disposal. If this method returns false, meaning that a layout is not required, then layout configuration will be skipped even if there is available layout configuration information at the disposal of the configurator..

In the rather exceptional case, where the appender implementation admits a layout but can also work without it, then the appender should return true.

Implements log4cxx::Appender.

setEncoding()

void log4cxx::WriterAppender::setEncoding ( const LogString & value )

setImmediateFlush()

void log4cxx::WriterAppender::setImmediateFlush ( bool value )

If the ImmediateFlush option is set to true, the appender will flush at the end of each write.

This is the default behavior. If the option is set to false, then the underlying stream can defer writing to physical medium to a later time.

Avoiding the flush operation at the end of each append results in a performance gain of 10 to 20 percent. However, there is safety tradeoff involved in skipping flushing. Indeed, when flushing is skipped, then it is likely that the last few log events will not be recorded on disk when the application exits. This is a high price to pay even for a 20% performance gain.

setOption()

void log4cxx::WriterAppender::setOption ( const LogString & option, const LogString & value ) overridevirtual

Set option to value.

Supported options Supported values Default value
Encoding C,UTF-8,UTF-16,UTF-16BE,UTF-16LE,646,US-ASCII,ISO646-US,ANSI_X3.4-1968,ISO-8859-1,ISO-LATIN-1 UTF-8

See also

AppenderSkeleton::setOption()

Reimplemented from log4cxx::AppenderSkeleton.

setWriter()

void log4cxx::WriterAppender::setWriter ( const helpers::WriterPtr & writer )

Send log output to writer which must be open and be writable.

The helpers::Writer will be closed when the appender instance is closed.

WARNING: Logging to an unopened Writer will fail.

Parameters

writer An already opened Writer.

setWriterInternal()

void log4cxx::WriterAppender::setWriterInternal ( const helpers::WriterPtr & writer) protected

Set the writer.

Mutex must already be held.

subAppend()

writeFooter()

virtual void log4cxx::WriterAppender::writeFooter ( helpers::Pool & p) protectedvirtual

writeHeader()

virtual void log4cxx::WriterAppender::writeHeader ( helpers::Pool & p) protectedvirtual

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