Search in sources :

Example 6 with AppenderWrapper

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

the class SyslogAppenderBuilder method createAppender.

private Appender createAppender(final String name, final Log4j1Configuration configuration, Layout layout, String facility, final Filter filter, final String syslogHost, final String level, final Protocol protocol) {
    AtomicReference<String> host = new AtomicReference<>();
    AtomicInteger port = new AtomicInteger();
    resolveSyslogHost(syslogHost, host, port);
    org.apache.logging.log4j.core.Layout<? extends Serializable> appenderLayout;
    if (layout instanceof LayoutWrapper) {
        appenderLayout = ((LayoutWrapper) layout).getLayout();
    } else if (layout != null) {
        appenderLayout = new LayoutAdapter(layout);
    } else {
        appenderLayout = SyslogLayout.newBuilder().setFacility(Facility.toFacility(facility)).setConfiguration(configuration).build();
    }
    org.apache.logging.log4j.core.Filter fileFilter = buildFilters(level, filter);
    return new AppenderWrapper(SocketAppender.newBuilder().setName(name).setConfiguration(configuration).setLayout(appenderLayout).setFilter(fileFilter).setPort(port.get()).setProtocol(protocol).setHost(host.get()).build());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AppenderWrapper(org.apache.log4j.bridge.AppenderWrapper) AtomicReference(java.util.concurrent.atomic.AtomicReference) LayoutWrapper(org.apache.log4j.bridge.LayoutWrapper) LayoutAdapter(org.apache.log4j.bridge.LayoutAdapter)

Example 7 with AppenderWrapper

use of org.apache.log4j.bridge.AppenderWrapper 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

AppenderWrapper (org.apache.log4j.bridge.AppenderWrapper)7 Appender (org.apache.log4j.Appender)3 AppenderAdapter (org.apache.log4j.bridge.AppenderAdapter)3 LayoutAdapter (org.apache.log4j.bridge.LayoutAdapter)3 LayoutWrapper (org.apache.log4j.bridge.LayoutWrapper)3 CompositeTriggeringPolicy (org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy)2 DefaultRolloverStrategy (org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy)2 RolloverStrategy (org.apache.logging.log4j.core.appender.rolling.RolloverStrategy)2 TimeBasedTriggeringPolicy (org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy)2 TriggeringPolicy (org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 RewritePolicyAdapter (org.apache.log4j.bridge.RewritePolicyAdapter)1 RewritePolicyWrapper (org.apache.log4j.bridge.RewritePolicyWrapper)1 ErrorHandler (org.apache.log4j.spi.ErrorHandler)1 SizeBasedTriggeringPolicy (org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy)1 AppenderRef (org.apache.logging.log4j.core.config.AppenderRef)1 StatusConfiguration (org.apache.logging.log4j.core.config.status.StatusConfiguration)1