org.apache.log4j

Class AppenderSkeleton

Implemented Interfaces:
Appender, OptionHandler
Known Direct Subclasses:
AsyncAppender, JDBCAppender, JMSAppender, LF5Appender, NTEventLogAppender, NullAppender, NullAppender, SMTPAppender, SocketAppender, SocketHubAppender, SyslogAppender, TelnetAppender, WriterAppender

public abstract class AppenderSkeleton
extends Object
implements Appender, OptionHandler

Abstract superclass of the other appenders in the package. This class provides the code for common functionality, such as support for threshold filtering and support for general filters.
Author:
Ceki Gülcü
Since:
0.8.1

Field Summary

protected boolean
closed
Is this appender closed?
protected ErrorHandler
errorHandler
It is assumed and enforced that errorHandler is never null.
protected Filter
headFilter
The first filter in the filter chain.
protected Layout
layout
The layout variable does not need to be set if the appender implementation has its own layout.
protected String
name
Appenders are named.
protected Filter
tailFilter
The last filter in the filter chain.
protected Priority
threshold
There is no level threshold filtering by default.

Method Summary

void
activateOptions()
Derived appenders should override this method if option structure requires it.
void
addFilter(Filter newFilter)
Add a filter to end of the filter list.
protected abstract void
append(LoggingEvent event)
Subclasses of AppenderSkeleton should implement this method to perform actual logging.
void
clearFilters()
Clear the filters chain.
void
doAppend(LoggingEvent event)
This method performs threshold checks and invokes filters before delegating actual logging to the subclasses specific append(LoggingEvent) method.
void
finalize()
Finalize this appender by calling the derived class' close method.
ErrorHandler
getErrorHandler()
Return the currently set ErrorHandler for this Appender.
Filter
getFilter()
Returns the head Filter.
Filter
getFirstFilter()
Return the first filter in the filter chain for this Appender.
Layout
getLayout()
Returns the layout of this appender.
String
getName()
Returns the name of this FileAppender.
Priority
getThreshold()
Returns this appenders threshold level.
boolean
isAsSevereAsThreshold(Priority priority)
Check whether the message level is below the appender's threshold.
void
setErrorHandler(ErrorHandler eh)
Set the ErrorHandler for this Appender.
void
setLayout(Layout layout)
Set the layout for this appender.
void
setName(String name)
Set the name of this Appender.
void
setThreshold(Priority threshold)
Set the threshold level.

Field Details

closed

protected boolean closed
Is this appender closed?

errorHandler

protected ErrorHandler errorHandler
It is assumed and enforced that errorHandler is never null.

headFilter

protected Filter headFilter
The first filter in the filter chain. Set to null initially.

layout

protected Layout layout
The layout variable does not need to be set if the appender implementation has its own layout.

name

protected String name
Appenders are named.

tailFilter

protected Filter tailFilter
The last filter in the filter chain.

threshold

protected Priority threshold
There is no level threshold filtering by default.

Method Details

activateOptions

public void activateOptions()
Derived appenders should override this method if option structure requires it.
Specified by:
activateOptions in interface OptionHandler

addFilter

public void addFilter(Filter newFilter)
Add a filter to end of the filter list.
Specified by:
addFilter in interface Appender
Since:
0.9.0

append

protected abstract void append(LoggingEvent event)
Subclasses of AppenderSkeleton should implement this method to perform actual logging. See also AppenderSkeleton.doAppend method.
Since:
0.9.0

clearFilters

public void clearFilters()
Clear the filters chain.
Specified by:
clearFilters in interface Appender
Since:
0.9.0

doAppend

public void doAppend(LoggingEvent event)
This method performs threshold checks and invokes filters before delegating actual logging to the subclasses specific append(LoggingEvent) method.
Specified by:
doAppend in interface Appender

finalize

public void finalize()
Finalize this appender by calling the derived class' close method.
Since:
0.8.4

getErrorHandler

public ErrorHandler getErrorHandler()
Return the currently set ErrorHandler for this Appender.
Specified by:
getErrorHandler in interface Appender
Since:
0.9.0

getFilter

public Filter getFilter()
Returns the head Filter.
Specified by:
getFilter in interface Appender
Since:
1.1

getFirstFilter

public final 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.

getLayout

public Layout getLayout()
Returns the layout of this appender. The value may be null.
Specified by:
getLayout in interface Appender

getName

public final String getName()
Returns the name of this FileAppender.
Specified by:
getName in interface Appender

getThreshold

public Priority getThreshold()
Returns this appenders threshold level. See the setThreshold(Priority) method for the meaning of this option.
Since:
1.1

isAsSevereAsThreshold

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

setErrorHandler

public void setErrorHandler(ErrorHandler eh)
Set the ErrorHandler for this Appender.
Specified by:
setErrorHandler in interface Appender
Since:
0.9.0

setLayout

public void setLayout(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 Appender

setName

public void setName(String name)
Set the name of this Appender.
Specified by:
setName in interface Appender

setThreshold

public void setThreshold(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

Copyright 2000-2005 Apache Software Foundation.