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;
}
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);
}
}
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();
}
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");
}
}
Aggregations