FileDocCategorySizeDatePackage
AppenderAttachableImpl.javaAPI DocApache log4j 1.2.154584Sat Aug 25 00:09:40 BST 2007org.apache.log4j.helpers

AppenderAttachableImpl

public class AppenderAttachableImpl extends Object implements AppenderAttachable
A straightforward implementation of the {@link AppenderAttachable} interface.
author
Ceki Gülcü
since
version 0.9.1

Fields Summary
protected Vector
appenderList
Array of appenders.
Constructors Summary
Methods Summary
public voidaddAppender(org.apache.log4j.Appender newAppender)
Attach an appender. If the appender is already in the list in won't be added again.

    // Null values for newAppender parameter are strictly forbidden.
    if(newAppender == null)
      return;
    
    if(appenderList == null) {
      appenderList = new Vector(1);
    }
    if(!appenderList.contains(newAppender))
      appenderList.addElement(newAppender);
  
public intappendLoopOnAppenders(org.apache.log4j.spi.LoggingEvent event)
Call the doAppend method on all attached appenders.

    int size = 0;
    Appender appender;

    if(appenderList != null) {
      size = appenderList.size();
      for(int i = 0; i < size; i++) {
	appender = (Appender) appenderList.elementAt(i);
	appender.doAppend(event);
      }
    }    
    return size;
  
public java.util.EnumerationgetAllAppenders()
Get all attached appenders as an Enumeration. If there are no attached appenders null is returned.

return
Enumeration An enumeration of attached appenders.

    if(appenderList == null)
      return null;
    else 
      return appenderList.elements();    
  
public org.apache.log4j.AppendergetAppender(java.lang.String name)
Look for an attached appender named as name.

Return the appender with that name if in the list. Return null otherwise.

     if(appenderList == null || name == null)
      return null;

     int size = appenderList.size();
     Appender appender;
     for(int i = 0; i < size; i++) {
       appender = (Appender) appenderList.elementAt(i);
       if(name.equals(appender.getName()))
	  return appender;
     }
     return null;    
  
public booleanisAttached(org.apache.log4j.Appender appender)
Returns true if the specified appender is in the list of attached appenders, false otherwise.

since
1.2

    if(appenderList == null || appender == null)
      return false;

     int size = appenderList.size();
     Appender a;
     for(int i = 0; i < size; i++) {
       a  = (Appender) appenderList.elementAt(i);
       if(a == appender)
	  return true;
     }
     return false;    
  
public voidremoveAllAppenders()
Remove and close all previously attached appenders.

    if(appenderList != null) {
      int len = appenderList.size();      
      for(int i = 0; i < len; i++) {
	Appender a = (Appender) appenderList.elementAt(i);
	a.close();
      }
      appenderList.removeAllElements();
      appenderList = null;      
    }
  
public voidremoveAppender(org.apache.log4j.Appender appender)
Remove the appender passed as parameter form the list of attached appenders.

    if(appender == null || appenderList == null) 
      return;
    appenderList.removeElement(appender);    
  
public voidremoveAppender(java.lang.String name)
Remove the appender with the name passed as parameter form the list of appenders.

    if(name == null || appenderList == null) return;
    int size = appenderList.size();
    for(int i = 0; i < size; i++) {
      if(name.equals(((Appender)appenderList.elementAt(i)).getName())) {
	 appenderList.removeElementAt(i);
	 break;
      }
    }