org.apache.log4j.spi.AppenderAttachable Java Examples

The following examples show how to use org.apache.log4j.spi.AppenderAttachable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Category.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
    Close all attached appenders implementing the AppenderAttachable
    interface.
    @since 1.0
 */
 synchronized
 void closeNestedAppenders() {
   Enumeration enumeration = this.getAllAppenders();
   if(enumeration != null) {
     while(enumeration.hasMoreElements()) {
Appender a = (Appender) enumeration.nextElement();
if(a instanceof AppenderAttachable) {
  a.close();
}
     }
   }
 }
 
Example #2
Source File: DOMConfigurator.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
    Used internally to parse an appender element.
  */
 protected
 Appender parseAppender (Element appenderElement) {
   String className = subst(appenderElement.getAttribute(CLASS_ATTR));
   LogLog.debug("Class name: [" + className+']');    
   try {
     Object instance 	= Loader.loadClass(className).newInstance();
     Appender appender	= (Appender)instance;
     PropertySetter propSetter = new PropertySetter(appender);

     appender.setName(subst(appenderElement.getAttribute(NAME_ATTR)));
     
     NodeList children	= appenderElement.getChildNodes();
     final int length 	= children.getLength();

     for (int loop = 0; loop < length; loop++) {
Node currentNode = children.item(loop);

/* We're only interested in Elements */
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
  Element currentElement = (Element)currentNode;

  // Parse appender parameters 
  if (currentElement.getTagName().equals(PARAM_TAG)) {
           setParameter(currentElement, propSetter);
  }
  // Set appender layout
  else if (currentElement.getTagName().equals(LAYOUT_TAG)) {
    appender.setLayout(parseLayout(currentElement));
  }
  // Add filters
  else if (currentElement.getTagName().equals(FILTER_TAG)) {
    parseFilters(currentElement, appender);
  }
  else if (currentElement.getTagName().equals(ERROR_HANDLER_TAG)) {
    parseErrorHandler(currentElement, appender);
  }
  else if (currentElement.getTagName().equals(APPENDER_REF_TAG)) {
    String refName = subst(currentElement.getAttribute(REF_ATTR));
    if(appender instanceof AppenderAttachable) {
      AppenderAttachable aa = (AppenderAttachable) appender;
      LogLog.debug("Attaching appender named ["+ refName+
		   "] to appender named ["+ appender.getName()+"].");
      aa.addAppender(findAppenderByReference(currentElement));
    } else {
      LogLog.error("Requesting attachment of appender named ["+
		   refName+ "] to appender named ["+ appender.getName()+
               "] which does not implement org.apache.log4j.spi.AppenderAttachable.");
    }
  } else {
         parseUnrecognizedElement(instance, currentElement, props);
     }
}
     }
     propSetter.activate();
     return appender;
   }
   /* Yes, it's ugly.  But all of these exceptions point to the same
      problem: we can't create an Appender */
   catch (Exception oops) {
     LogLog.error("Could not create an Appender. Reported error follows.",
	   oops);
     return null;
   }
 }