Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Class Members | Related Pages

WriterAppender Class Reference

Inheritance diagram for WriterAppender:

AppenderSkeleton Appender ObjectImpl OptionHandler Object Object ConsoleAppender FileAppender DailyRollingFileAppender RollingFileAppender List of all members.

Public Member Functions

 WriterAppender ()
 WriterAppender (const LayoutPtr &layout, ostream *os)
void setImmediateFlush (bool value)
bool getImmediateFlush () const
virtual void append (const spi::LoggingEventPtr &event)
virtual void close ()
virtual bool requiresLayout () const

Protected Member Functions

virtual bool checkEntryConditions () const
virtual void closeWriter ()=0
virtual void subAppend (const spi::LoggingEventPtr &event)
virtual void reset ()
virtual void writeFooter ()
virtual void writeHeader ()

Protected Attributes

bool immediateFlush
String encoding
ostream * os

Detailed Description

WriterAppender appends log events to a standard output stream (ostream or wostream)


Constructor & Destructor Documentation

WriterAppender  ) 
 

This default constructor does nothing.

WriterAppender const LayoutPtr layout,
ostream *  os
 

Instantiate a WriterAppender and set the output destination to os.


Member Function Documentation

void append const spi::LoggingEventPtr event  )  [virtual]
 

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

bool checkEntryConditions  )  const [protected, virtual]
 

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.

void close  )  [virtual]
 

Close this appender instance. The underlying stream or writer is also closed.

Closed appenders cannot be reused.

Implements Appender.

virtual void closeWriter  )  [protected, pure virtual]
 

Close the underlying output stream.

Implemented in ConsoleAppender, and FileAppender.

bool getImmediateFlush  )  const [inline]
 

Returns value of the ImmediateFlush option.

virtual bool requiresLayout  )  const [inline, virtual]
 

The WriterAppender requires a layout. Hence, this method returns true.

Implements Appender.

void reset  )  [protected, virtual]
 

Clear internal references to the writer and other variables.

Subclasses can override this method for an alternate closing behavior.

void setImmediateFlush bool  value  )  [inline]
 

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.

void subAppend const spi::LoggingEventPtr event  )  [protected, virtual]
 

Actual writing occurs here.

Most subclasses of WriterAppender will need to override this method.

Reimplemented in DailyRollingFileAppender, and RollingFileAppender.

void writeFooter  )  [protected, virtual]
 

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

void writeHeader  )  [protected, virtual]
 

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


Member Data Documentation

String encoding [protected]
 

The encoding to use when opening an input stream.

The encoding variable is set to "" by default which results in the utilization of the system's default encoding.

bool immediateFlush [protected]
 

Immediate flush means that the underlying writer or output stream will be flushed at the end of each append operation. Immediate flush is slower but ensures that each append request is actually written. If immediateFlush is set to

false, then there is a good chance that the last few logs events are not actually written to persistent media if and when the application crashes.

The immediateFlush variable is set to true by default.

ostream* os [protected]
 

This is the output stream where we will write to.


The documentation for this class was generated from the following files:
Generated on Tue Nov 14 14:55:20 2006 for log4cxx by  doxygen 1.3.9.1