Search in sources :

Example 6 with AppenderControl

use of org.apache.logging.log4j.core.config.AppenderControl in project logging-log4j2 by apache.

the class FailoverAppender method start.

@Override
public void start() {
    final Map<String, Appender> map = config.getAppenders();
    int errors = 0;
    final Appender appender = map.get(primaryRef);
    if (appender != null) {
        primary = new AppenderControl(appender, null, null);
    } else {
        LOGGER.error("Unable to locate primary Appender " + primaryRef);
        ++errors;
    }
    for (final String name : failovers) {
        final Appender foAppender = map.get(name);
        if (foAppender != null) {
            failoverAppenders.add(new AppenderControl(foAppender, null, null));
        } else {
            LOGGER.error("Failover appender " + name + " is not configured");
        }
    }
    if (failoverAppenders.isEmpty()) {
        LOGGER.error("No failover appenders are available");
        ++errors;
    }
    if (errors == 0) {
        super.start();
    }
}
Also used : Appender(org.apache.logging.log4j.core.Appender) AppenderControl(org.apache.logging.log4j.core.config.AppenderControl)

Example 7 with AppenderControl

use of org.apache.logging.log4j.core.config.AppenderControl in project logging-log4j2 by apache.

the class RewriteAppender method start.

@Override
public void start() {
    for (final AppenderRef ref : appenderRefs) {
        final String name = ref.getRef();
        final Appender appender = config.getAppender(name);
        if (appender != null) {
            final Filter filter = appender instanceof AbstractAppender ? ((AbstractAppender) appender).getFilter() : null;
            appenders.put(name, new AppenderControl(appender, ref.getLevel(), filter));
        } else {
            LOGGER.error("Appender " + ref + " cannot be located. Reference ignored");
        }
    }
    super.start();
}
Also used : AbstractAppender(org.apache.logging.log4j.core.appender.AbstractAppender) Appender(org.apache.logging.log4j.core.Appender) AppenderControl(org.apache.logging.log4j.core.config.AppenderControl) Filter(org.apache.logging.log4j.core.Filter) AbstractAppender(org.apache.logging.log4j.core.appender.AbstractAppender) AppenderRef(org.apache.logging.log4j.core.config.AppenderRef)

Example 8 with AppenderControl

use of org.apache.logging.log4j.core.config.AppenderControl in project logging-log4j2 by apache.

the class LoggerConfigBenchmark method setup.

@Setup
public void setup() {
    listAppender.start();
    final AppenderControl control = new AppenderControl(listAppender, Level.ALL, null);
    appenderSet.add(control);
}
Also used : AppenderControl(org.apache.logging.log4j.core.config.AppenderControl) Setup(org.openjdk.jmh.annotations.Setup)

Example 9 with AppenderControl

use of org.apache.logging.log4j.core.config.AppenderControl in project logging-log4j2 by apache.

the class RoutesScriptAppenderTest method getListAppender.

private ListAppender getListAppender() {
    final String key = "Service2";
    final RoutingAppender routingAppender = getRoutingAppender();
    Assert.assertTrue(routingAppender.isStarted());
    final Map<String, AppenderControl> appenders = routingAppender.getAppenders();
    final AppenderControl appenderControl = appenders.get(key);
    assertNotNull("No appender control generated for '" + key + "'; appenders = " + appenders, appenderControl);
    final ListAppender listAppender = (ListAppender) appenderControl.getAppender();
    return listAppender;
}
Also used : AppenderControl(org.apache.logging.log4j.core.config.AppenderControl) ListAppender(org.apache.logging.log4j.test.appender.ListAppender)

Example 10 with AppenderControl

use of org.apache.logging.log4j.core.config.AppenderControl in project hive by apache.

the class LlapWrappedAppender method setupAppenderIfRequired.

private void setupAppenderIfRequired(LogEvent event) {
    if (appenderControl.get() == null) {
        if (node.getType().getElementName().equalsIgnoreCase("appender")) {
            for (final Node cnode : node.getChildren()) {
                final Node appNode = new Node(cnode);
                config.createConfiguration(appNode, event);
                if (appNode.getObject() instanceof Appender) {
                    final Appender app = appNode.getObject();
                    app.start();
                    if (!(app instanceof RandomAccessFileAppender)) {
                        String message = "Cannot handle appenders other than " + RandomAccessFileAppender.class.getName() + ". Found: " + app.getClass().getName();
                        LOGGER.error(message);
                        throw new IllegalStateException(message);
                    }
                    realAppender.set(app);
                    appenderControl.set(new AppenderControl(app, null, null));
                    if (LOGGER.isDebugEnabled()) {
                        RandomAccessFileAppender raf = (RandomAccessFileAppender) app;
                        LOGGER.debug("Setup new appender to write to file: " + raf.getFileName() + ", appenderName=" + raf.getName() + ", appenderManagerName=" + raf.getManager().getName());
                    }
                    break;
                }
            }
            if (appenderControl.get() == null) {
                // Fail if mis-configured.
                throw new RuntimeException(LlapWrappedAppender.class.getSimpleName() + "name=" + getName() + " unable to setup actual appender." + "Could not find child appender");
            }
        } else {
            // Fail if mis-configured.
            throw new RuntimeException(LlapWrappedAppender.class.getSimpleName() + "name=" + getName() + " unable to setup actual appender." + "Could not find child appender");
        }
    }
}
Also used : AbstractAppender(org.apache.logging.log4j.core.appender.AbstractAppender) Appender(org.apache.logging.log4j.core.Appender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) AppenderControl(org.apache.logging.log4j.core.config.AppenderControl) PluginNode(org.apache.logging.log4j.core.config.plugins.PluginNode) Node(org.apache.logging.log4j.core.config.Node)

Aggregations

AppenderControl (org.apache.logging.log4j.core.config.AppenderControl)14 Appender (org.apache.logging.log4j.core.Appender)8 AbstractAppender (org.apache.logging.log4j.core.appender.AbstractAppender)5 Map (java.util.Map)2 AppenderRef (org.apache.logging.log4j.core.config.AppenderRef)2 ListAppender (org.apache.logging.log4j.test.appender.ListAppender)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Bindings (javax.script.Bindings)1 IgniteLogger (org.apache.ignite.IgniteLogger)1 LoggingException (org.apache.logging.log4j.LoggingException)1 Filter (org.apache.logging.log4j.core.Filter)1 LifeCycle2 (org.apache.logging.log4j.core.LifeCycle2)1 Logger (org.apache.logging.log4j.core.Logger)1 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)1 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)1 RandomAccessFileAppender (org.apache.logging.log4j.core.appender.RandomAccessFileAppender)1 RollingFileAppender (org.apache.logging.log4j.core.appender.RollingFileAppender)1