FileDocCategorySizeDatePackage
AppenderSkeleton.javaAPI DocApache log4j 1.2.157110Sat Aug 25 00:09:42 BST 2007org.apache.log4j

AppenderSkeleton

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.
since
0.8.1
author
Ceki Gülcü

Fields Summary
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 Priority
threshold
There is no level threshold filtering by default.
protected ErrorHandler
errorHandler
It is assumed and enforced that errorHandler is never null.
protected Filter
headFilter
The first filter in the filter chain. Set to null initially.
protected Filter
tailFilter
The last filter in the filter chain.
protected boolean
closed
Is this appender closed?
Constructors Summary
public AppenderSkeleton()
Create new instance.


            
      
        super();
    
protected AppenderSkeleton(boolean isActive)
Create new instance. Provided for compatibility with log4j 1.3.

param
isActive true if appender is ready for use upon construction. Not used in log4j 1.2.x.
since
1.2.15

        super();
    
Methods Summary
public voidactivateOptions()
Derived appenders should override this method if option structure requires it.

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

since
0.9.0

    if(headFilter == null) {
      headFilter = tailFilter = newFilter;
    } else {
      tailFilter.setNext(newFilter);
      tailFilter = newFilter;    
    }
  
protected abstract voidappend(org.apache.log4j.spi.LoggingEvent event)
Subclasses of AppenderSkeleton should implement this method to perform actual logging. See also {@link #doAppend AppenderSkeleton.doAppend} method.

since
0.9.0

public voidclearFilters()
Clear the filters chain.

since
0.9.0

    headFilter = tailFilter = null;
  
public synchronized voiddoAppend(org.apache.log4j.spi.LoggingEvent event)
This method performs threshold checks and invokes filters before delegating actual logging to the subclasses specific {@link AppenderSkeleton#append} method.

    if(closed) {
      LogLog.error("Attempted to append to closed appender named ["+name+"].");
      return;
    }
    
    if(!isAsSevereAsThreshold(event.getLevel())) {
      return;
    }

    Filter f = this.headFilter;
    
    FILTER_LOOP:
    while(f != null) {
      switch(f.decide(event)) {
      case Filter.DENY: return;
      case Filter.ACCEPT: break FILTER_LOOP;
      case Filter.NEUTRAL: f = f.getNext();
      }
    }
    
    this.append(event);    
  
public voidfinalize()
Finalize this appender by calling the derived class' close method.

since
0.8.4

    // An appender might be closed then garbage collected. There is no
    // point in closing twice.
    if(this.closed) 
      return;

    LogLog.debug("Finalizing appender named ["+name+"].");
    close();
  
public org.apache.log4j.spi.ErrorHandlergetErrorHandler()
Return the currently set {@link ErrorHandler} for this Appender.

since
0.9.0

    return this.errorHandler;
  
public org.apache.log4j.spi.FiltergetFilter()
Returns the head Filter.

since
1.1

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

    return headFilter;
  
public org.apache.log4j.LayoutgetLayout()
Returns the layout of this appender. The value may be null.

    return layout;
  
public final java.lang.StringgetName()
Returns the name of this FileAppender.

    return this.name;
  
public org.apache.log4j.PrioritygetThreshold()
Returns this appenders threshold level. See the {@link #setThreshold} method for the meaning of this option.

since
1.1

    return threshold;
  
public booleanisAsSevereAsThreshold(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.

    return ((threshold == null) || priority.isGreaterOrEqual(threshold));
  
public synchronized voidsetErrorHandler(org.apache.log4j.spi.ErrorHandler eh)
Set the {@link ErrorHandler} for this Appender.

since
0.9.0

    if(eh == null) {
      // We do not throw exception here since the cause is probably a
      // bad config file.
      LogLog.warn("You have tried to set a null error-handler.");
    } else {
      this.errorHandler = eh;
    }
  
public voidsetLayout(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 {@link org.apache.log4j.net.SocketAppender} ignores the layout set here.

    this.layout = layout;
  
public voidsetName(java.lang.String name)
Set the name of this Appender.

    this.name = name;
  
public voidsetThreshold(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

    this.threshold = threshold;