Search in sources :

Example 11 with AppenderControl

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

the class DefaultRouteScriptAppenderTest 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 12 with AppenderControl

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

the class RoutingAppender method append.

@Override
public void append(LogEvent event) {
    if (rewritePolicy != null) {
        event = rewritePolicy.rewrite(event);
    }
    final String pattern = routes.getPattern(event, scriptStaticVariables);
    final String key = pattern != null ? configuration.getStrSubstitutor().replace(event, pattern) : defaultRoute.getKey();
    final AppenderControl control = getControl(key, event);
    if (control != null) {
        control.callAppender(event);
    }
    if (purgePolicy != null) {
        purgePolicy.update(key, event);
    }
}
Also used : AppenderControl(org.apache.logging.log4j.core.config.AppenderControl)

Example 13 with AppenderControl

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

the class RoutingAppender method start.

@Override
public void start() {
    if (defaultRouteScript != null) {
        if (configuration == null) {
            error("No Configuration defined for RoutingAppender; required for Script element.");
        } else {
            final ScriptManager scriptManager = configuration.getScriptManager();
            scriptManager.addScript(defaultRouteScript);
            final Bindings bindings = scriptManager.createBindings(defaultRouteScript);
            bindings.put(STATIC_VARIABLES_KEY, scriptStaticVariables);
            final Object object = scriptManager.execute(defaultRouteScript.getName(), bindings);
            final Route route = routes.getRoute(Objects.toString(object, null));
            if (route != null) {
                defaultRoute = route;
            }
        }
    }
    // Register all the static routes.
    for (final Route route : routes.getRoutes()) {
        if (route.getAppenderRef() != null) {
            final Appender appender = configuration.getAppender(route.getAppenderRef());
            if (appender != null) {
                final String key = route == defaultRoute ? DEFAULT_KEY : route.getKey();
                appenders.put(key, new AppenderControl(appender, null, null));
            } else {
                error("Appender " + route.getAppenderRef() + " cannot be located. Route 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) ScriptManager(org.apache.logging.log4j.core.script.ScriptManager) Bindings(javax.script.Bindings)

Example 14 with AppenderControl

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

the class RoutingAppender method deleteAppender.

/**
     * Deletes the specified appender.
     *
     * @param key The appender's key
     */
public void deleteAppender(final String key) {
    LOGGER.debug("Deleting route with " + key + " key ");
    final AppenderControl control = appenders.remove(key);
    if (null != control) {
        LOGGER.debug("Stopping route with " + key + " key");
        control.getAppender().stop();
    } else {
        LOGGER.debug("Route with " + key + " key already deleted");
    }
}
Also used : AppenderControl(org.apache.logging.log4j.core.config.AppenderControl)

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