Java Code Examples for org.apache.log4j.spi.ErrorHandler#setAppender()

The following examples show how to use org.apache.log4j.spi.ErrorHandler#setAppender() . 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: XmlConfiguration.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
/**
 * Used internally to parse an {@link ErrorHandler} element.
 */
private void parseErrorHandler(Element element, Appender appender) {
    ErrorHandler eh = (ErrorHandler) OptionConverter.instantiateByClassName(
            subst(element.getAttribute(CLASS_ATTR)),
            ErrorHandler.class,
            null);

    if (eh != null) {
        eh.setAppender(appender);

        PropertySetter propSetter = new PropertySetter(eh);
        forEachElement(element.getChildNodes(), (currentElement) -> {
            String tagName = currentElement.getTagName();
            if (tagName.equals(PARAM_TAG)) {
                setParameter(currentElement, propSetter);
            }
        });
        propSetter.activate();
        appender.setErrorHandler(eh);
    }
}
 
Example 2
Source File: XmlConfigurationFactory.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
/**
 * Used internally to parse an {@link ErrorHandler} element.
 */
private void parseErrorHandler(Element element, Appender appender) {
    ErrorHandler eh = (ErrorHandler) OptionConverter.instantiateByClassName(
            subst(element.getAttribute(CLASS_ATTR)),
            ErrorHandler.class,
            null);

    if (eh != null) {
        eh.setAppender(appender);

        PropertySetter propSetter = new PropertySetter(eh);
        forEachElement(element.getChildNodes(), (currentElement) -> {
            String tagName = currentElement.getTagName();
            if (tagName.equals(PARAM_TAG)) {
                setParameter(currentElement, propSetter);
            }
        });
        propSetter.activate();
        appender.setErrorHandler(eh);
    }
}
 
Example 3
Source File: FallbackAppender.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor
 */
public FallbackAppender() {
    ErrorHandler fb = new FallbackErrorHandler();
    this.setErrorHandler(fb);
    fb.setAppender(this);
    Appender rootAppen = Logger.getRootLogger().getAppender("RootAppender");

    if (rootAppen != null) {
        fb.setBackupAppender(rootAppen);
    }

    Logger logger = Logger.getLogger(LoggingInvocationProcessor.class);
    fb.setLogger(logger);
}
 
Example 4
Source File: FailbackAppender.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor
 */
public FailbackAppender() {
    ErrorHandler fb = new FallbackErrorHandler();
    this.setErrorHandler(fb);
    fb.setAppender(this);
    Appender rootAppen = Logger.getRootLogger().getAppender("RootAppender");

    if (rootAppen != null) {
        fb.setBackupAppender(rootAppen);
    }

    Logger logger = Logger.getLogger(LoggingInvocationProcessor.class);
    fb.setLogger(logger);
}
 
Example 5
Source File: FallbackAppender.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor
 */
public FallbackAppender() {
    ErrorHandler fb = new FallbackErrorHandler();
    this.setErrorHandler(fb);
    fb.setAppender(this);
    Appender rootAppen = Logger.getRootLogger().getAppender("RootAppender");

    if (rootAppen != null) {
        fb.setBackupAppender(rootAppen);
    }

    Logger logger = Logger.getLogger(LoggingInvocationProcessor.class);
    fb.setLogger(logger);
}
 
Example 6
Source File: FailbackAppender.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor
 */
public FailbackAppender() {
    ErrorHandler fb = new FallbackErrorHandler();
    this.setErrorHandler(fb);
    fb.setAppender(this);
    Appender rootAppen = Logger.getRootLogger().getAppender("RootAppender");

    if (rootAppen != null) {
        fb.setBackupAppender(rootAppen);
    }

    Logger logger = Logger.getLogger(LoggingInvocationProcessor.class);
    fb.setLogger(logger);
}
 
Example 7
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 {@link ErrorHandler} element.
  */
 protected
 void parseErrorHandler(Element element, Appender appender) {
   ErrorHandler eh = (ErrorHandler) OptionConverter.instantiateByClassName(
                                      subst(element.getAttribute(CLASS_ATTR)),
                                      org.apache.log4j.spi.ErrorHandler.class, 
				       null);
   
   if(eh != null) {
     eh.setAppender(appender);

     PropertySetter propSetter = new PropertySetter(eh);
     NodeList children = element.getChildNodes();
     final int length 	= children.getLength();

     for (int loop = 0; loop < length; loop++) {
Node currentNode = children.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 if(tagName.equals(APPENDER_REF_TAG)) {
    eh.setBackupAppender(findAppenderByReference(currentElement));
  } else if(tagName.equals(LOGGER_REF)) {
    String loggerName = currentElement.getAttribute(REF_ATTR);	    
    Logger logger = (catFactory == null) ? repository.getLogger(loggerName)
               : repository.getLogger(loggerName, catFactory);
    eh.setLogger(logger);
  } else if(tagName.equals(ROOT_REF)) {
    Logger root = repository.getRootLogger();
    eh.setLogger(root);
  } else {
         quietParseUnrecognizedElement(eh, currentElement, props);
     }
}
     }
     propSetter.activate();
     appender.setErrorHandler(eh);
   }
 }