Java 类org.apache.log4j.spi.ThrowableRenderer 实例源码

项目:daq-eclipse    文件:DOMConfigurator.java   
/**
 * Parses throwable renderer.
 * @param element throwableRenderer element.
 * @return configured throwable renderer.
 * @since 1.2.16.
 */
protected ThrowableRenderer parseThrowableRenderer(final Element element) {
    String className = subst(element.getAttribute(CLASS_ATTR));
    LogLog.debug("Parsing throwableRenderer of class: \""+className+"\"");
    try {
      Object instance   = Loader.loadClass(className).newInstance();
      ThrowableRenderer tr      = (ThrowableRenderer)instance;
      PropertySetter propSetter = new PropertySetter(tr);

      NodeList params   = element.getChildNodes();
      final int length  = params.getLength();

      for (int loop = 0; loop < length; loop++) {
            Node currentNode = (Node)params.item(loop);
            if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
                Element currentElement = (Element) currentNode;
                String tagName = currentElement.getTagName();
                if(tagName.equals(PARAM_TAG)) {
                    setParameter(currentElement, propSetter);
                } else {
                    parseUnrecognizedElement(instance, currentElement, props);
                }
            }
      }

      propSetter.activate();
      return tr;
    }
    catch (Exception oops) {
        if (oops instanceof InterruptedException || oops instanceof InterruptedIOException) {
            Thread.currentThread().interrupt();
        }
        LogLog.error("Could not create the ThrowableRenderer. Reported error follows.",
           oops);
      return null;
    }
}
项目:daq-eclipse    文件:PropertyConfigurator.java   
/**
    Parse non-root elements, such non-root categories and renderers.
 */
 protected
 void parseCatsAndRenderers(Properties props, LoggerRepository hierarchy) {
   Enumeration enumeration = props.propertyNames();
   while(enumeration.hasMoreElements()) {
     String key = (String) enumeration.nextElement();
     if(key.startsWith(CATEGORY_PREFIX) || key.startsWith(LOGGER_PREFIX)) {
String loggerName = null;
if(key.startsWith(CATEGORY_PREFIX)) {
  loggerName = key.substring(CATEGORY_PREFIX.length());
} else if(key.startsWith(LOGGER_PREFIX)) {
  loggerName = key.substring(LOGGER_PREFIX.length());
}
String value =  OptionConverter.findAndSubst(key, props);
Logger logger = hierarchy.getLogger(loggerName, loggerFactory);
synchronized(logger) {
  parseCategory(props, logger, key, loggerName, value);
  parseAdditivityForLogger(props, logger, loggerName);
}
     } else if(key.startsWith(RENDERER_PREFIX)) {
String renderedClass = key.substring(RENDERER_PREFIX.length());
String renderingClass = OptionConverter.findAndSubst(key, props);
if(hierarchy instanceof RendererSupport) {
  RendererMap.addRenderer((RendererSupport) hierarchy, renderedClass,
              renderingClass);
}
     } else if (key.equals(THROWABLE_RENDERER_PREFIX)) {
         if (hierarchy instanceof ThrowableRendererSupport) {
           ThrowableRenderer tr = (ThrowableRenderer)
                 OptionConverter.instantiateByKey(props,
                         THROWABLE_RENDERER_PREFIX,
                         org.apache.log4j.spi.ThrowableRenderer.class,
                         null);
           if(tr == null) {
               LogLog.error(
                   "Could not instantiate throwableRenderer.");
           } else {
               PropertySetter setter = new PropertySetter(tr);
               setter.setProperties(props, THROWABLE_RENDERER_PREFIX + ".");
               ((ThrowableRendererSupport) hierarchy).setThrowableRenderer(tr);

           }
         }
     }
   }
 }
项目:daq-eclipse    文件:Hierarchy.java   
/**
   * {@inheritDoc}
   */
public void setThrowableRenderer(final ThrowableRenderer renderer) {
    throwableRenderer = renderer;
}
项目:daq-eclipse    文件:Hierarchy.java   
/**
   * {@inheritDoc}
   */
public ThrowableRenderer getThrowableRenderer() {
    return throwableRenderer;
}