Search in sources :

Example 1 with EvaluatorFilter

use of ch.qos.logback.core.filter.EvaluatorFilter in project uplace.es by Uplace.

the class LoggingConfiguration method setMetricsMarkerLogbackFilter.

// Configure a log filter to remove "metrics" logs from all appenders except the "LOGSTASH" appender
private void setMetricsMarkerLogbackFilter(LoggerContext context) {
    log.info("Filtering metrics logs from all appenders except the {} appender", LOGSTASH_APPENDER_NAME);
    OnMarkerEvaluator onMarkerMetricsEvaluator = new OnMarkerEvaluator();
    onMarkerMetricsEvaluator.setContext(context);
    onMarkerMetricsEvaluator.addMarker("metrics");
    onMarkerMetricsEvaluator.start();
    EvaluatorFilter<ILoggingEvent> metricsFilter = new EvaluatorFilter<>();
    metricsFilter.setContext(context);
    metricsFilter.setEvaluator(onMarkerMetricsEvaluator);
    metricsFilter.setOnMatch(FilterReply.DENY);
    metricsFilter.start();
    for (ch.qos.logback.classic.Logger logger : context.getLoggerList()) {
        for (Iterator<Appender<ILoggingEvent>> it = logger.iteratorForAppenders(); it.hasNext(); ) {
            Appender<ILoggingEvent> appender = it.next();
            if (!appender.getName().equals(ASYNC_LOGSTASH_APPENDER_NAME)) {
                log.debug("Filter metrics logs from the {} appender", appender.getName());
                appender.setContext(context);
                appender.addFilter(metricsFilter);
                appender.start();
            }
        }
    }
}
Also used : LogstashTcpSocketAppender(net.logstash.logback.appender.LogstashTcpSocketAppender) Appender(ch.qos.logback.core.Appender) AsyncAppender(ch.qos.logback.classic.AsyncAppender) OnMarkerEvaluator(ch.qos.logback.classic.boolex.OnMarkerEvaluator) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) EvaluatorFilter(ch.qos.logback.core.filter.EvaluatorFilter)

Aggregations

AsyncAppender (ch.qos.logback.classic.AsyncAppender)1 OnMarkerEvaluator (ch.qos.logback.classic.boolex.OnMarkerEvaluator)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 Appender (ch.qos.logback.core.Appender)1 EvaluatorFilter (ch.qos.logback.core.filter.EvaluatorFilter)1 LogstashTcpSocketAppender (net.logstash.logback.appender.LogstashTcpSocketAppender)1