Search in sources :

Example 6 with ErrorHandler

use of org.apache.log4j.spi.ErrorHandler in project logging-log4j2 by apache.

the class PropertyConfigurator method parseAppender.

Appender parseAppender(final Properties properties, final String appenderName) {
    Appender appender = registryGet(appenderName);
    if ((appender != null)) {
        LogLog.debug("Appender \"" + appenderName + "\" was already parsed.");
        return appender;
    }
    // Appender was not previously initialized.
    final String prefix = APPENDER_PREFIX + appenderName;
    final String layoutPrefix = prefix + ".layout";
    appender = (Appender) OptionConverter.instantiateByKey(properties, prefix, org.apache.log4j.Appender.class, null);
    if (appender == null) {
        LogLog.error("Could not instantiate appender named \"" + appenderName + "\".");
        return null;
    }
    appender.setName(appenderName);
    if (appender instanceof OptionHandler) {
        if (appender.requiresLayout()) {
            final Layout layout = (Layout) OptionConverter.instantiateByKey(properties, layoutPrefix, Layout.class, null);
            if (layout != null) {
                appender.setLayout(layout);
                LogLog.debug("Parsing layout options for \"" + appenderName + "\".");
                // configureOptionHandler(layout, layoutPrefix + ".", props);
                PropertySetter.setProperties(layout, properties, layoutPrefix + ".");
                LogLog.debug("End of parsing for \"" + appenderName + "\".");
            }
        }
        final String errorHandlerPrefix = prefix + ".errorhandler";
        final String errorHandlerClass = OptionConverter.findAndSubst(errorHandlerPrefix, properties);
        if (errorHandlerClass != null) {
            final ErrorHandler eh = (ErrorHandler) OptionConverter.instantiateByKey(properties, errorHandlerPrefix, ErrorHandler.class, null);
            if (eh != null) {
                appender.setErrorHandler(eh);
                LogLog.debug("Parsing errorhandler options for \"" + appenderName + "\".");
                parseErrorHandler(eh, errorHandlerPrefix, properties, repository);
                final Properties edited = new Properties();
                final String[] keys = new String[] { errorHandlerPrefix + "." + ROOT_REF, errorHandlerPrefix + "." + LOGGER_REF, errorHandlerPrefix + "." + APPENDER_REF_TAG };
                for (final Object element : properties.entrySet()) {
                    final Map.Entry entry = (Map.Entry) element;
                    int i = 0;
                    for (; i < keys.length; i++) {
                        if (keys[i].equals(entry.getKey())) {
                            break;
                        }
                    }
                    if (i == keys.length) {
                        edited.put(entry.getKey(), entry.getValue());
                    }
                }
                PropertySetter.setProperties(eh, edited, errorHandlerPrefix + ".");
                LogLog.debug("End of errorhandler parsing for \"" + appenderName + "\".");
            }
        }
        // configureOptionHandler((OptionHandler) appender, prefix + ".", props);
        PropertySetter.setProperties(appender, properties, prefix + ".");
        LogLog.debug("Parsed \"" + appenderName + "\" options.");
    }
    parseAppenderFilters(properties, appenderName, appender);
    registryPut(appender);
    return appender;
}
Also used : ErrorHandler(org.apache.log4j.spi.ErrorHandler) OptionHandler(org.apache.log4j.spi.OptionHandler) Properties(java.util.Properties) RendererMap(org.apache.log4j.or.RendererMap) Map(java.util.Map)

Aggregations

ErrorHandler (org.apache.log4j.spi.ErrorHandler)6 Appender (org.apache.log4j.Appender)3 HashSet (java.util.HashSet)2 Layout (org.apache.log4j.Layout)2 Filter (org.apache.log4j.spi.Filter)2 LoggingEvent (org.apache.log4j.spi.LoggingEvent)2 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)2 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)2 NonManagedPluginRegistry (org.datanucleus.plugin.NonManagedPluginRegistry)2 Map (java.util.Map)1 Properties (java.util.Properties)1 AppenderAdapter (org.apache.log4j.bridge.AppenderAdapter)1 AppenderWrapper (org.apache.log4j.bridge.AppenderWrapper)1 PropertySetter (org.apache.log4j.config.PropertySetter)1 RendererMap (org.apache.log4j.or.RendererMap)1 OptionHandler (org.apache.log4j.spi.OptionHandler)1