Java 类org.apache.logging.log4j.core.config.AppenderControl 实例源码

项目:log4j2    文件:RewriteAppender.java   
@Override
public void start() {
    final Map<String, Appender> map = config.getAppenders();
    for (final AppenderRef ref : appenderRefs) {
        final String name = ref.getRef();
        final Appender appender = map.get(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();
}
项目:log4j2    文件:RoutingAppender.java   
@Override
public void start() {
    final Map<String, Appender> map = config.getAppenders();
    // Register all the static routes.
    for (final Route route : routes.getRoutes()) {
        if (route.getAppenderRef() != null) {
            final Appender appender = map.get(route.getAppenderRef());
            if (appender != null) {
                final String key = route == defaultRoute ? DEFAULT_KEY : route.getKey();
                appenders.put(key, new AppenderControl(appender, null, null));
            } else {
                LOGGER.error("Appender " + route.getAppenderRef() + " cannot be located. Route ignored");
            }
        }
    }
    super.start();
}
项目:log4j2    文件:FailoverAppender.java   
@Override
public void start() {
    final Map<String, Appender> map = config.getAppenders();
    int errors = 0;
    if (map.containsKey(primaryRef)) {
        primary = new AppenderControl(map.get(primaryRef), null, null);
    } else {
        LOGGER.error("Unable to locate primary Appender " + primaryRef);
        ++errors;
    }
    for (final String name : failovers) {
        if (map.containsKey(name)) {
            failoverAppenders.add(new AppenderControl(map.get(name), null, null));
        } else {
            LOGGER.error("Failover appender " + name + " is not configured");
        }
    }
    if (failoverAppenders.size() == 0) {
        LOGGER.error("No failover appenders are available");
        ++errors;
    }
    if (errors == 0) {
        super.start();
    }
}
项目:log4j2    文件:FailoverAppender.java   
private void failover(final LogEvent event, final Exception ex) {
    final RuntimeException re = ex != null ?
            (ex instanceof LoggingException ? (LoggingException)ex : new LoggingException(ex)) : null;
    boolean written = false;
    Exception failoverException = null;
    for (final AppenderControl control : failoverAppenders) {
        try {
            control.callAppender(event);
            written = true;
            break;
        } catch (final Exception fex) {
            if (failoverException == null) {
                failoverException = fex;
            }
        }
    }
    if (!written && !ignoreExceptions()) {
        if (re != null) {
            throw re;
        } else {
            throw new LoggingException("Unable to write to failover appenders", failoverException);
        }
    }
}
项目:logging-log4j2    文件:RoutingAppender.java   
@Override
public boolean stop(final long timeout, final TimeUnit timeUnit) {
    setStopping();
    super.stop(timeout, timeUnit, false);
    final Map<String, Appender> map = configuration.getAppenders();
    for (final Map.Entry<String, AppenderControl> entry : appenders.entrySet()) {
        final Appender appender = entry.getValue().getAppender();
        if (!map.containsKey(appender.getName())) {
            if (appender instanceof LifeCycle2) {
                ((LifeCycle2) appender).stop(timeout, timeUnit);
            } else {
                appender.stop();
            }
        }
    }
    setStopped();
    return true;
}
项目:logging-log4j2    文件:RoutingAppender.java   
@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);
    }
}
项目:logging-log4j2    文件:FailoverAppender.java   
private void failover(final LogEvent event, final Exception ex) {
    final RuntimeException re = ex != null ?
            (ex instanceof LoggingException ? (LoggingException) ex : new LoggingException(ex)) : null;
    boolean written = false;
    Exception failoverException = null;
    for (final AppenderControl control : failoverAppenders) {
        try {
            control.callAppender(event);
            written = true;
            break;
        } catch (final Exception fex) {
            if (failoverException == null) {
                failoverException = fex;
            }
        }
    }
    if (!written && !ignoreExceptions()) {
        if (re != null) {
            throw re;
        }
        throw new LoggingException("Unable to write to failover appenders", failoverException);
    }
}
项目:ignite    文件:Log4J2Logger.java   
/** {@inheritDoc} */
@Nullable @Override public String fileName() {
    for (Logger log = impl; log != null; log = log.getParent()) {
        for (Appender a : log.getAppenders().values()) {
            if (a instanceof FileAppender)
                return ((FileAppender)a).getFileName();

            if (a instanceof RollingFileAppender)
                return ((RollingFileAppender)a).getFileName();

            if (a instanceof RoutingAppender) {
                try {
                    RoutingAppender routing = (RoutingAppender)a;

                    Field appsFiled = routing.getClass().getDeclaredField("appenders");

                    appsFiled.setAccessible(true);

                    Map<String, AppenderControl> appenders = (Map<String, AppenderControl>)appsFiled.get(routing);

                    for (AppenderControl control : appenders.values()) {
                        Appender innerApp = control.getAppender();

                        if (innerApp instanceof FileAppender)
                            return normalize(((FileAppender)innerApp).getFileName());

                        if (innerApp instanceof RollingFileAppender)
                            return normalize(((RollingFileAppender)innerApp).getFileName());
                    }
                }
                catch (IllegalAccessException | NoSuchFieldException e) {
                    error("Failed to get file name (was the implementation of log4j2 changed?).", e);
                }
            }
        }
    }

    return null;
}
项目:log4j2    文件:AsyncAppender.java   
@Override
public void start() {
    final Map<String, Appender> map = config.getAppenders();
    final List<AppenderControl> appenders = new ArrayList<AppenderControl>();
    for (final AppenderRef appenderRef : appenderRefs) {
        if (map.containsKey(appenderRef.getRef())) {
            appenders.add(new AppenderControl(map.get(appenderRef.getRef()), appenderRef.getLevel(),
                appenderRef.getFilter()));
        } else {
            LOGGER.error("No appender named {} was configured", appenderRef);
        }
    }
    if (errorRef != null) {
        if (map.containsKey(errorRef)) {
            errorAppender = new AppenderControl(map.get(errorRef), null, null);
        } else {
            LOGGER.error("Unable to set up error Appender. No appender named {} was configured", errorRef);
        }
    }
    if (appenders.size() > 0) {
        thread = new AsyncThread(appenders, queue);
        thread.setName("AsyncAppender-" + getName());
    } else if (errorRef == null) {
        throw new ConfigurationException("No appenders are available for AsyncAppender " + getName());
    }

    thread.start();
    super.start();
}
项目:log4j2    文件:RewriteAppender.java   
/**
 * Modify the event and pass to the subordinate Appenders.
 * @param event The LogEvent.
 */
@Override
public void append(LogEvent event) {
    if (rewritePolicy != null) {
        event = rewritePolicy.rewrite(event);
    }
    for (final AppenderControl control : appenders.values()) {
        control.callAppender(event);
    }
}
项目:log4j2    文件:RoutingAppender.java   
@Override
public void stop() {
    super.stop();
    final Map<String, Appender> map = config.getAppenders();
    for (final Map.Entry<String, AppenderControl> entry : appenders.entrySet()) {
        final String name = entry.getValue().getAppender().getName();
        if (!map.containsKey(name)) {
            entry.getValue().getAppender().stop();
        }
    }
}
项目:log4j2    文件:RoutingAppender.java   
@Override
public void append(LogEvent event) {
    if (rewritePolicy != null) {
        event = rewritePolicy.rewrite(event);
    }
    final String key = config.getStrSubstitutor().replace(event, routes.getPattern());
    final AppenderControl control = getControl(key, event);
    if (control != null) {
        control.callAppender(event);
    }
}
项目:logging-log4j2    文件:LoggerConfigBenchmark.java   
@Setup
public void setup() {

    listAppender.start();
    final AppenderControl control = new AppenderControl(listAppender, Level.ALL, null);
    appenderSet.add(control);
}
项目:logging-log4j2    文件:AsyncAppender.java   
/**
 * Calls {@link AppenderControl#callAppender(LogEvent) callAppender} on all registered {@code AppenderControl}
 * objects, and returns {@code true} if at least one appender call was successful, {@code false} otherwise. Any
 * exceptions are silently ignored.
 *
 * @param event the event to forward to the registered appenders
 * @return {@code true} if at least one appender call succeeded, {@code false} otherwise
 */
boolean callAppenders(final LogEvent event) {
    boolean success = false;
    for (final AppenderControl control : appenders) {
        try {
            control.callAppender(event);
            success = true;
        } catch (final Exception ex) {
            // If no appender is successful the error appender will get it.
        }
    }
    return success;
}
项目:logging-log4j2    文件:RewriteAppender.java   
@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();
}
项目:logging-log4j2    文件:RewriteAppender.java   
/**
 * Modifies the event and pass to the subordinate Appenders.
 * @param event The LogEvent.
 */
@Override
public void append(LogEvent event) {
    if (rewritePolicy != null) {
        event = rewritePolicy.rewrite(event);
    }
    for (final AppenderControl control : appenders.values()) {
        control.callAppender(event);
    }
}
项目:logging-log4j2    文件:RoutingAppender.java   
/**
 * 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");
    }
}
项目:logging-log4j2    文件:FailoverAppender.java   
@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();
    }
}
项目:logging-log4j2    文件:DefaultRouteScriptAppenderTest.java   
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;
}
项目:logging-log4j2    文件:RoutesScriptAppenderTest.java   
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;
}
项目:log4j2    文件:AsyncAppender.java   
public AsyncThread(final List<AppenderControl> appenders, final BlockingQueue<Serializable> queue) {
    this.appenders = appenders;
    this.queue = queue;
    setDaemon(true);
    setName("AsyncAppenderThread" + threadSequence.getAndIncrement());
}
项目:logging-log4j2    文件:LoggerConfigBenchmark.java   
protected void callAppenders(final LogEvent event) {
    for (final AppenderControl control : appenderSet) {
        control.callAppender(event);
    }
}
项目:logging-log4j2    文件:AsyncAppender.java   
public AsyncThread(final List<AppenderControl> appenders, final BlockingQueue<LogEvent> queue) {
    super("AsyncAppender-" + THREAD_SEQUENCE.getAndIncrement());
    this.appenders = appenders;
    this.queue = queue;
    setDaemon(true);
}
项目:logging-log4j2    文件:RoutingAppender.java   
public Map<String, AppenderControl> getAppenders() {
    return Collections.unmodifiableMap(appenders);
}