Search in sources :

Example 1 with AppenderAdapter

use of org.apache.log4j.bridge.AppenderAdapter in project logging-log4j2 by apache.

the class PropertiesConfiguration method buildAppender.

private Appender buildAppender(final String appenderName, final String className, final String prefix, final String layoutPrefix, final String filterPrefix, final Properties props) {
    final Appender appender = newInstanceOf(className, "Appender");
    if (appender == null) {
        return null;
    }
    appender.setName(appenderName);
    appender.setLayout(parseLayout(layoutPrefix, appenderName, props));
    final String errorHandlerPrefix = prefix + ".errorhandler";
    final String errorHandlerClass = OptionConverter.findAndSubst(errorHandlerPrefix, props);
    if (errorHandlerClass != null) {
        final ErrorHandler eh = parseErrorHandler(props, errorHandlerPrefix, errorHandlerClass, appender);
        if (eh != null) {
            appender.setErrorHandler(eh);
        }
    }
    appender.addFilter(parseAppenderFilters(props, filterPrefix, appenderName));
    final 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;
}
Also used : Appender(org.apache.log4j.Appender) ErrorHandler(org.apache.log4j.spi.ErrorHandler) AppenderWrapper(org.apache.log4j.bridge.AppenderWrapper) AppenderAdapter(org.apache.log4j.bridge.AppenderAdapter)

Example 2 with AppenderAdapter

use of org.apache.log4j.bridge.AppenderAdapter in project logging-log4j2 by apache.

the class PropertiesConfiguration method parseAppender.

public Appender parseAppender(final Properties props, final String appenderName) {
    Appender appender = registry.get(appenderName);
    if ((appender != null)) {
        LOGGER.debug("Appender \"" + appenderName + "\" was already parsed.");
        return appender;
    }
    // Appender was not previously initialized.
    final String prefix = APPENDER_PREFIX + appenderName;
    final String layoutPrefix = prefix + ".layout";
    final String filterPrefix = APPENDER_PREFIX + appenderName + ".filter.";
    final String className = OptionConverter.findAndSubst(prefix, props);
    appender = manager.parseAppender(appenderName, className, prefix, layoutPrefix, filterPrefix, props, this);
    if (appender == null) {
        appender = buildAppender(appenderName, className, prefix, layoutPrefix, filterPrefix, props);
    } else {
        registry.put(appenderName, appender);
        if (appender instanceof AppenderWrapper) {
            addAppender(((AppenderWrapper) appender).getAppender());
        } else {
            addAppender(new AppenderAdapter(appender).getAdapter());
        }
    }
    return appender;
}
Also used : Appender(org.apache.log4j.Appender) AppenderWrapper(org.apache.log4j.bridge.AppenderWrapper) AppenderAdapter(org.apache.log4j.bridge.AppenderAdapter)

Example 3 with AppenderAdapter

use of org.apache.log4j.bridge.AppenderAdapter in project logging-log4j2 by apache.

the class XmlConfiguration method parse.

/**
 * Used internally to configure the log4j framework by parsing a DOM
 * tree of XML elements based on <a
 * href="doc-files/log4j.dtd">log4j.dtd</a>.
 */
private void parse(Element element) {
    String rootElementName = element.getTagName();
    if (!rootElementName.equals(CONFIGURATION_TAG)) {
        if (rootElementName.equals(OLD_CONFIGURATION_TAG)) {
            LOGGER.warn("The <" + OLD_CONFIGURATION_TAG + "> element has been deprecated.");
            LOGGER.warn("Use the <" + CONFIGURATION_TAG + "> element instead.");
        } else {
            LOGGER.error("DOM element is - not a <" + CONFIGURATION_TAG + "> element.");
            return;
        }
    }
    String debugAttrib = subst(element.getAttribute(INTERNAL_DEBUG_ATTR));
    LOGGER.debug("debug attribute= \"" + debugAttrib + "\".");
    // if the log4j.dtd is not specified in the XML file, then the
    // "debug" attribute is returned as the empty string.
    String status = "error";
    if (!debugAttrib.equals("") && !debugAttrib.equals("null")) {
        status = OptionConverter.toBoolean(debugAttrib, true) ? "debug" : "error";
    } else {
        LOGGER.debug("Ignoring " + INTERNAL_DEBUG_ATTR + " attribute.");
    }
    String confDebug = subst(element.getAttribute(CONFIG_DEBUG_ATTR));
    if (!confDebug.equals("") && !confDebug.equals("null")) {
        LOGGER.warn("The \"" + CONFIG_DEBUG_ATTR + "\" attribute is deprecated.");
        LOGGER.warn("Use the \"" + INTERNAL_DEBUG_ATTR + "\" attribute instead.");
        status = OptionConverter.toBoolean(confDebug, true) ? "debug" : "error";
    }
    final StatusConfiguration statusConfig = new StatusConfiguration().setStatus(status);
    statusConfig.initialize();
    forEachElement(element.getChildNodes(), (currentElement) -> {
        switch(currentElement.getTagName()) {
            case CATEGORY:
            case LOGGER_ELEMENT:
                parseCategory(currentElement);
                break;
            case ROOT_TAG:
                parseRoot(currentElement);
                break;
            case RENDERER_TAG:
                LOGGER.warn("Renderers are not supported by Log4j 2 and will be ignored.");
                break;
            case THROWABLE_RENDERER_TAG:
                LOGGER.warn("Throwable Renderers are not supported by Log4j 2 and will be ignored.");
                break;
            case CATEGORY_FACTORY_TAG:
            case LOGGER_FACTORY_TAG:
                LOGGER.warn("Log4j 1 Logger factories are not supported by Log4j 2 and will be ignored.");
                break;
            case APPENDER_TAG:
                Appender appender = parseAppender(currentElement);
                appenderMap.put(appender.getName(), appender);
                if (appender instanceof AppenderWrapper) {
                    addAppender(((AppenderWrapper) appender).getAppender());
                } else {
                    addAppender(new AppenderAdapter(appender).getAdapter());
                }
                break;
            default:
                quietParseUnrecognizedElement(null, currentElement, props);
        }
    });
}
Also used : Appender(org.apache.log4j.Appender) AppenderWrapper(org.apache.log4j.bridge.AppenderWrapper) StatusConfiguration(org.apache.logging.log4j.core.config.status.StatusConfiguration) AppenderAdapter(org.apache.log4j.bridge.AppenderAdapter)

Aggregations

Appender (org.apache.log4j.Appender)3 AppenderAdapter (org.apache.log4j.bridge.AppenderAdapter)3 AppenderWrapper (org.apache.log4j.bridge.AppenderWrapper)3 ErrorHandler (org.apache.log4j.spi.ErrorHandler)1 StatusConfiguration (org.apache.logging.log4j.core.config.status.StatusConfiguration)1