org.apache.log4j.spi.ErrorHandler Java Examples

The following examples show how to use org.apache.log4j.spi.ErrorHandler. 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: 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 #2
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 #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: WriterAppender.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Set the {@link ErrorHandler} for this WriterAppender and also the
 * underlying {@link QuietWriter} if any.
 */
public synchronized void setErrorHandler(ErrorHandler eh) {
    if (eh == null) {
        LOGGER.warn("You have tried to set a null error-handler.");
    } else {
        this.errorHandler = eh;
        if (this.qw != null) {
            this.qw.setErrorHandler(eh);
        }
    }
}
 
Example #5
Source File: PropertySetter.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Convert <code>val</code> a String parameter to an object of a
 * given type.
 */
protected Object convertArg(String val, Class type) {
    if (val == null) {
        return null;
    }

    String v = val.trim();
    if (String.class.isAssignableFrom(type)) {
        return val;
    } else if (Integer.TYPE.isAssignableFrom(type)) {
        return Integer.parseInt(v);
    } else if (Long.TYPE.isAssignableFrom(type)) {
        return Long.parseLong(v);
    } else if (Boolean.TYPE.isAssignableFrom(type)) {
        if ("true".equalsIgnoreCase(v)) {
            return Boolean.TRUE;
        } else if ("false".equalsIgnoreCase(v)) {
            return Boolean.FALSE;
        }
    } else if (Priority.class.isAssignableFrom(type)) {
        return org.apache.log4j.helpers.OptionConverter.toLevel(v, Level.DEBUG);
    } else if (ErrorHandler.class.isAssignableFrom(type)) {
        return OptionConverter.instantiateByClassName(v,
                ErrorHandler.class, null);
    }
    return null;
}
 
Example #6
Source File: QuietWriter.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public
void setErrorHandler(ErrorHandler eh) {
  if(eh == null) {
    // This is a programming error on the part of the enclosing appender.
    throw new IllegalArgumentException("Attempted to set null ErrorHandler.");
  } else { 
    this.errorHandler = eh;
  }
}
 
Example #7
Source File: AppenderSkeleton.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Set the {@link ErrorHandler} for this Appender.
 *
 * @since 0.9.0
 */
@Override
public synchronized void setErrorHandler(final ErrorHandler eh) {
    if (eh != null) {
        this.errorHandler = eh;
    }
}
 
Example #8
Source File: WriterAppender.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
    Set the {@link ErrorHandler} for this WriterAppender and also the
    underlying {@link QuietWriter} if any. */
 public synchronized void setErrorHandler(ErrorHandler eh) {
   if(eh == null) {
     LogLog.warn("You have tried to set a null error-handler.");
   } else {
     this.errorHandler = eh;
     if(this.qw != null) {
this.qw.setErrorHandler(eh);
     }
   }
 }
 
Example #9
Source File: AppenderSkeleton.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** 
    Set the {@link ErrorHandler} for this Appender.
    @since 0.9.0
*/
public
synchronized
void setErrorHandler(ErrorHandler eh) {
  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;
  }
}
 
Example #10
Source File: QuietWriter.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
public void setErrorHandler(ErrorHandler eh) {
    if (eh == null) {
        // This is a programming error on the part of the enclosing appender.
        throw new IllegalArgumentException("Attempted to set null ErrorHandler.");
    } else {
        this.errorHandler = eh;
    }
}
 
Example #11
Source File: PropertySetter.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Convert <code>val</code> a String parameter to an object of a
 * given type.
 * @param val The value to convert.
 * @param type The type of the value to convert to.
 * @return The result of the conversion.
 */
protected Object convertArg(String val, Class<?> type) {
    if (val == null) {
        return null;
    }

    String v = val.trim();
    if (String.class.isAssignableFrom(type)) {
        return val;
    } else if (Integer.TYPE.isAssignableFrom(type)) {
        return Integer.parseInt(v);
    } else if (Long.TYPE.isAssignableFrom(type)) {
        return Long.parseLong(v);
    } else if (Boolean.TYPE.isAssignableFrom(type)) {
        if ("true".equalsIgnoreCase(v)) {
            return Boolean.TRUE;
        } else if ("false".equalsIgnoreCase(v)) {
            return Boolean.FALSE;
        }
    } else if (Priority.class.isAssignableFrom(type)) {
        return org.apache.log4j.helpers.OptionConverter.toLevel(v, Level.DEBUG);
    } else if (ErrorHandler.class.isAssignableFrom(type)) {
        return OptionConverter.instantiateByClassName(v,
                ErrorHandler.class, null);
    }
    return null;
}
 
Example #12
Source File: PropertiesConfiguration.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private Appender buildAppender(final String appenderName, final String className, final String prefix,
        final String layoutPrefix, final String filterPrefix, final Properties props) {
    Appender appender = newInstanceOf(className, "Appender");
    if (appender == null) {
        return null;
    }
    appender.setName(appenderName);
    appender.setLayout(parseLayout(layoutPrefix, appenderName, props));
    final String errorHandlerPrefix = prefix + ".errorhandler";
    String errorHandlerClass = OptionConverter.findAndSubst(errorHandlerPrefix, props);
    if (errorHandlerClass != null) {
        ErrorHandler eh = parseErrorHandler(props, errorHandlerPrefix, errorHandlerClass, appender);
        if (eh != null) {
            appender.setErrorHandler(eh);
        }
    }
    parseAppenderFilters(props, filterPrefix, appenderName);
    String[] keys = new String[] {
            layoutPrefix,
    };
    addProperties(appender, keys, props, prefix);
    if (appender instanceof AppenderWrapper) {
        addAppender(((AppenderWrapper) appender).getAppender());
    } else {
        addAppender(new AppenderAdapter(appender).getAdapter());
    }
    registry.put(appenderName, appender);
    return appender;
}
 
Example #13
Source File: PropertiesConfiguration.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
public ErrorHandler parseErrorHandler(final Properties props, final String errorHandlerPrefix,
        final String errorHandlerClass, final Appender appender) {
    ErrorHandler eh = newInstanceOf(errorHandlerClass, "ErrorHandler");
    final String[] keys = new String[] {
            errorHandlerPrefix + "." + ROOT_REF,
            errorHandlerPrefix + "." + LOGGER_REF,
            errorHandlerPrefix + "." + APPENDER_REF_TAG
    };
    addProperties(eh, keys, props, errorHandlerPrefix);
    return eh;
}
 
Example #14
Source File: WriterAppender.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Set the {@link ErrorHandler} for this WriterAppender and also the
 * underlying {@link QuietWriter} if any.
 */
public synchronized void setErrorHandler(ErrorHandler eh) {
    if (eh == null) {
        LOGGER.warn("You have tried to set a null error-handler.");
    } else {
        this.errorHandler = eh;
        if (this.qw != null) {
            this.qw.setErrorHandler(eh);
        }
    }
}
 
Example #15
Source File: AppenderSkeleton.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Set the {@link ErrorHandler} for this Appender.
 *
 * @since 0.9.0
 */
@Override
public synchronized void setErrorHandler(final ErrorHandler eh) {
    if (eh != null) {
        this.errorHandler = eh;
    }
}
 
Example #16
Source File: QuietWriter.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
public void setErrorHandler(ErrorHandler eh) {
    if (eh == null) {
        // This is a programming error on the part of the enclosing appender.
        throw new IllegalArgumentException("Attempted to set null ErrorHandler.");
    } else {
        this.errorHandler = eh;
    }
}
 
Example #17
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 #18
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 #19
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 #20
Source File: AppenderWrapper.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public void setErrorHandler(ErrorHandler errorHandler) {
    appender.setHandler(new ErrorHandlerAdapter(errorHandler));
}
 
Example #21
Source File: AppenderWrapper.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public ErrorHandler getErrorHandler() {
    return ((ErrorHandlerAdapter)appender.getHandler()).getHandler();
}
 
Example #22
Source File: AppenderSkeleton.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public ErrorHandler getErrorHandler() {
    return this.errorHandler;
}
 
Example #23
Source File: ErrorHandlerAdapter.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
public ErrorHandler getHandler() {
    return errorHandler;
}
 
Example #24
Source File: QuietWriter.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
public QuietWriter(Writer writer, ErrorHandler errorHandler) {
    super(writer);
    setErrorHandler(errorHandler);
}
 
Example #25
Source File: Log4jConsoleAppender.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public ErrorHandler getErrorHandler() {
  return null;
}
 
Example #26
Source File: Log4jConsoleAppender.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void setErrorHandler( ErrorHandler arg0 ) {
}
 
Example #27
Source File: Log4jPipedAppender.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public ErrorHandler getErrorHandler() {
  return null;
}
 
Example #28
Source File: Log4jPipedAppender.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void setErrorHandler( ErrorHandler arg0 ) {
}
 
Example #29
Source File: Log4jStringAppender.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void setErrorHandler( ErrorHandler arg0 ) {
}
 
Example #30
Source File: Log4jFileAppender.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public ErrorHandler getErrorHandler() {
  return null;
}