com.motlin.base.log4j
Class StdOutErrAppender

java.lang.Object
  extended by com.motlin.base.log4j.StdOutErrAppender
All Implemented Interfaces:
org.apache.log4j.Appender, org.apache.log4j.spi.OptionHandler

public final class StdOutErrAppender
extends Object
implements org.apache.log4j.Appender, org.apache.log4j.spi.OptionHandler

ConsoleAppender appends log events to System.out or System.err using a layout specified by the user.

Author:
Craig P. Motlin

Field Summary
static String SYSTEM_ERR
           
static String SYSTEM_OUT
           
 
Constructor Summary
StdOutErrAppender()
          Constructs an unconfigured appender.
StdOutErrAppender(org.apache.log4j.Layout layout)
          Creates a configured appender.
 
Method Summary
 void activateOptions()
           
 void addFilter(org.apache.log4j.spi.Filter newFilter)
          Add a filter to end of the filter list.
 void append(org.apache.log4j.spi.LoggingEvent event)
          This method is called by the AppenderSkeleton.doAppend(org.apache.log4j.spi.LoggingEvent) method.
 void clearFilters()
          Clear the filters chain.
 void close()
          Close this appender instance.
 void doAppend(org.apache.log4j.spi.LoggingEvent event)
          This method performs threshold checks and invokes filters before delegating actual logging to the subclasses specific AppenderSkeleton.append(org.apache.log4j.spi.LoggingEvent) method.
 String getEncoding()
           
 org.apache.log4j.spi.ErrorHandler getErrorHandler()
          Return the currently set ErrorHandler for this Appender.
 org.apache.log4j.spi.Filter getFilter()
          Returns the head Filter.
 org.apache.log4j.spi.Filter getFirstFilter()
          Return the first filter in the filter chain for this Appender.
 boolean getImmediateFlush()
          Returns value of the ImmediateFlush option.
 org.apache.log4j.Layout getLayout()
          Returns the layout of this appender.
 String getName()
          Returns the name of this FileAppender.
 org.apache.log4j.Priority getThreshold()
          Returns this appenders threshold level.
 boolean isAsSevereAsThreshold(org.apache.log4j.Priority priority)
          Check whether the message level is below the appender's threshold.
 boolean requiresLayout()
          The WriterAppender requires a layout.
 void setEncoding(String value)
           
 void setErrorHandler(org.apache.log4j.spi.ErrorHandler errorHandler)
          Set the ErrorHandler for this WriterAppender and also the underlying QuietWriter if any.
 void setImmediateFlush(boolean value)
          If the ImmediateFlush option is set to true, the appender will flush at the end of each write.
 void setLayout(org.apache.log4j.Layout layout)
          Set the layout for this appender.
 void setName(String name)
          Set the name of this Appender.
 void setThreshold(org.apache.log4j.Priority threshold)
          Set the threshold level.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SYSTEM_OUT

public static final String SYSTEM_OUT
See Also:
Constant Field Values

SYSTEM_ERR

public static final String SYSTEM_ERR
See Also:
Constant Field Values
Constructor Detail

StdOutErrAppender

public StdOutErrAppender()
Constructs an unconfigured appender.


StdOutErrAppender

public StdOutErrAppender(org.apache.log4j.Layout layout)
Creates a configured appender.

Parameters:
layout - layout, may not be null.
Method Detail

activateOptions

public void activateOptions()
Specified by:
activateOptions in interface org.apache.log4j.spi.OptionHandler

addFilter

public void addFilter(org.apache.log4j.spi.Filter newFilter)
Add a filter to end of the filter list.

Specified by:
addFilter in interface org.apache.log4j.Appender

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.


clearFilters

public void clearFilters()
Clear the filters chain.

Specified by:
clearFilters in interface org.apache.log4j.Appender

close

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

Specified by:
close in interface org.apache.log4j.Appender

doAppend

public void doAppend(org.apache.log4j.spi.LoggingEvent event)
This method performs threshold checks and invokes filters before delegating actual logging to the subclasses specific AppenderSkeleton.append(org.apache.log4j.spi.LoggingEvent) method.

Specified by:
doAppend in interface org.apache.log4j.Appender

getEncoding

public String getEncoding()

getErrorHandler

public org.apache.log4j.spi.ErrorHandler getErrorHandler()
Return the currently set ErrorHandler for this Appender.

Specified by:
getErrorHandler in interface org.apache.log4j.Appender

getFilter

public org.apache.log4j.spi.Filter getFilter()
Returns the head Filter.

Specified by:
getFilter in interface org.apache.log4j.Appender

getFirstFilter

public org.apache.log4j.spi.Filter getFirstFilter()
Return the first filter in the filter chain for this Appender. The return value may be null if no is filter is set.


getImmediateFlush

public boolean getImmediateFlush()
Returns value of the ImmediateFlush option.


getLayout

public org.apache.log4j.Layout getLayout()
Returns the layout of this appender. The value may be null.

Specified by:
getLayout in interface org.apache.log4j.Appender

getName

public String getName()
Returns the name of this FileAppender.

Specified by:
getName in interface org.apache.log4j.Appender

getThreshold

public org.apache.log4j.Priority getThreshold()
Returns this appenders threshold level. This is the threshold at which we switch from out to err.


isAsSevereAsThreshold

public boolean isAsSevereAsThreshold(org.apache.log4j.Priority priority)
Check whether the message level is below the appender's threshold. If there is no threshold set, then the return value is always true.


requiresLayout

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

Specified by:
requiresLayout in interface org.apache.log4j.Appender

setEncoding

public void setEncoding(String value)

setErrorHandler

public void setErrorHandler(org.apache.log4j.spi.ErrorHandler errorHandler)
Set the ErrorHandler for this WriterAppender and also the underlying QuietWriter if any.

Specified by:
setErrorHandler in interface org.apache.log4j.Appender

setImmediateFlush

public void setImmediateFlush(boolean 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.


setLayout

public void setLayout(org.apache.log4j.Layout layout)
Set the layout for this appender. Note that some appenders have their own (fixed) layouts or do not use one. For example, the SocketAppender ignores the layout set here.

Specified by:
setLayout in interface org.apache.log4j.Appender

setName

public void setName(String name)
Set the name of this Appender.

Specified by:
setName in interface org.apache.log4j.Appender

setThreshold

public void setThreshold(org.apache.log4j.Priority threshold)
Set the threshold level. All log events with lower level than the threshold level are ignored by the appender.

In configuration files this option is specified by setting the value of the Threshold option to a level string, such as "DEBUG", "INFO" and so on.

Since:
0.8.3