Apache Log4cxx  Version 1.2.0
Loading...
Searching...
No Matches
log4cxx::WriterAppender Class Reference

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

#include <writerappender.h>

Inheritance diagram for log4cxx::WriterAppender:
log4cxx::AppenderSkeleton log4cxx::Appender log4cxx::helpers::Object log4cxx::spi::OptionHandler log4cxx::helpers::Object log4cxx::ConsoleAppender log4cxx::FileAppender log4cxx::rolling::MultiprocessRollingFileAppender log4cxx::rolling::RollingFileAppender

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 log4cxx::helpers::WriterPtr &writer)
 
const log4cxx::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::ClassgetClass () 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, log4cxx::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 (helpers::OutputStreamPtr &os)
 Returns an OutputStreamWriter when passed an OutputStream.
 
virtual void subAppend (const spi::LoggingEventPtr &event, log4cxx::helpers::Pool &p)
 Actual writing occurs here.
 
virtual void writeFooter (log4cxx::helpers::Pool &p)
 Write a footer as produced by the embedded layout's Layout::appendFooter method.
 
virtual void writeHeader (log4cxx::helpers::Pool &p)
 Write a header as produced by the embedded layout's Layout::appendHeader method.
 
void setWriterInternal (const log4cxx::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)
 

Detailed Description

WriterAppender appends log events to a standard output stream.

Constructor & Destructor Documentation

◆ WriterAppender() [1/4]

log4cxx::WriterAppender::WriterAppender ( )

This default constructor does nothing.

◆ WriterAppender() [2/4]

log4cxx::WriterAppender::WriterAppender ( const LayoutPtr layout,
log4cxx::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 ( )

Member Function Documentation

◆ activateOptions()

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

Derived appenders should override this method if option structure requires it.

Reimplemented from log4cxx::AppenderSkeleton.

◆ append()

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

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

Close the underlying log4cxx::helpers::Writer.

◆ createWriter()

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

Returns an OutputStreamWriter when passed an OutputStream.

The encoding used will depend on the value of the encoding property. If the encoding value is specified incorrectly the writer will be opened using the default system encoding (an error message will be printed to the loglog.

Reimplemented in log4cxx::rolling::MultiprocessRollingFileAppender, and log4cxx::rolling::RollingFileAppender.

◆ 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 log4cxx::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)

Set the encoding to value.

See also
setOption

◆ 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 log4cxx::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
writerAn already opened Writer.

◆ setWriterInternal()

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

Set the writer.

Mutex must already be held.

◆ subAppend()

virtual void log4cxx::WriterAppender::subAppend ( const spi::LoggingEventPtr event,
log4cxx::helpers::Pool p 
)
protectedvirtual

◆ writeFooter()

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

Write a footer as produced by the embedded layout's Layout::appendFooter method.


◆ writeHeader()

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

Write a header as produced by the embedded layout's Layout::appendHeader method.



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