org.ceryle.util
Class MessageWriterAppender

java.lang.Object
  extended by org.apache.log4j.AppenderSkeleton
      extended by org.ceryle.util.MessageWriterAppender
All Implemented Interfaces:
org.apache.log4j.Appender, org.apache.log4j.spi.OptionHandler

public class MessageWriterAppender
extends org.apache.log4j.AppenderSkeleton

MessageWriterAppender appends log events to a MessageWriter.

Since:
1.0a12
Author:
Murray Altheim

Nested Class Summary
protected  class MessageWriterAppender.MWErrorHandler
          A quick and dirty inner class to implement ErrorHandler, which just spits its output to the underlying MessageWriter.
 
Field Summary
static String DEFAULT_PATTERN
          The default PatternLayout used when not supplied in the constructor.
protected  MessageWriter mw
          This is the MessageWriter where we will write to.
 
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
 
Constructor Summary
MessageWriterAppender(MessageWriter messagewriter)
          Constructor with a MessageWriter; this will use a default PatternLayout.
MessageWriterAppender(MessageWriter messagewriter, org.apache.log4j.Layout _layout)
          Instantiate a MessageWriterAppender and set the output destination to messagewriter.
 
Method Summary
 void activateOptions()
          Does nothing.
 void append(org.apache.log4j.spi.LoggingEvent event)
          This method is called by the AppenderSkeleton.doAppend(org.apache.log4j.spi.LoggingEvent) method.
protected  boolean checkEntryConditions()
          This method determines if there is a sense in attempting to append.
 void close()
          Close this appender instance.
 boolean requiresLayout()
          The MessageWriterAppender requires a layout.
protected  void reset()
          Clear internal references to the writer.
 void setErrorHandler(org.apache.log4j.spi.ErrorHandler eh)
          Set the MessageWriterAppender.MWErrorHandler for this MessageWriterAppender.
 void setMessageWriter(MessageWriter messagewriter)
          Sets the MessageWriter where the log output will go.
protected  void subAppend(org.apache.log4j.spi.LoggingEvent event)
          Actual writing occurs here.
protected  void writeFooter()
          Write a footer as produced by the embedded layout's Layout.getFooter() method.
protected  void writeHeader()
          Write a header as produced by the embedded layout's Layout.getHeader() method.
 
Methods inherited from class org.apache.log4j.AppenderSkeleton
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setLayout, setName, setThreshold
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PATTERN

public static final String DEFAULT_PATTERN
The default PatternLayout used when not supplied in the constructor. The value is: "%d %p [%c{1}] : %m%n"

See Also:
Constant Field Values

mw

protected MessageWriter mw
This is the MessageWriter where we will write to.

Constructor Detail

MessageWriterAppender

public MessageWriterAppender(MessageWriter messagewriter)
Constructor with a MessageWriter; this will use a default PatternLayout.


MessageWriterAppender

public MessageWriterAppender(MessageWriter messagewriter,
                             org.apache.log4j.Layout _layout)
Instantiate a MessageWriterAppender and set the output destination to messagewriter. The Layout is optional.

Method Detail

activateOptions

public void activateOptions()
Does nothing.

Specified by:
activateOptions in interface org.apache.log4j.spi.OptionHandler
Overrides:
activateOptions in class org.apache.log4j.AppenderSkeleton

append

public void append(org.apache.log4j.spi.LoggingEvent event)
This method is called by the AppenderSkeleton.doAppend(org.apache.log4j.spi.LoggingEvent) 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 System.err.

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

Specified by:
append in class org.apache.log4j.AppenderSkeleton

checkEntryConditions

protected boolean checkEntryConditions()
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

public void close()
Close this appender instance. The underlying stream or writer is also closed.

Closed appenders cannot be reused.

Since:
0.8.4
See Also:
setMessageWriter(org.ceryle.util.MessageWriter)

setErrorHandler

public void setErrorHandler(org.apache.log4j.spi.ErrorHandler eh)
Set the MessageWriterAppender.MWErrorHandler for this MessageWriterAppender.

Specified by:
setErrorHandler in interface org.apache.log4j.Appender
Overrides:
setErrorHandler in class org.apache.log4j.AppenderSkeleton

setMessageWriter

public void setMessageWriter(MessageWriter messagewriter)
Sets the MessageWriter where the log output will go.

Parameters:
messagewriter - an already opened MessageWriter.

subAppend

protected void subAppend(org.apache.log4j.spi.LoggingEvent event)
Actual writing occurs here.

Most subclasses of MessageWriterAppender will need to override this method.

Since:
0.9.0

requiresLayout

public boolean requiresLayout()
The MessageWriterAppender requires a layout. Hence, this method returns true.


reset

protected void reset()
Clear internal references to the writer.


writeFooter

protected void writeFooter()
Write a footer as produced by the embedded layout's Layout.getFooter() method.


writeHeader

protected void writeHeader()
Write a header as produced by the embedded layout's Layout.getHeader() method.



The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.