Java Code Examples for ch.qos.logback.core.filter.Filter#decide()

The following examples show how to use ch.qos.logback.core.filter.Filter#decide() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompositeFilter.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public FilterReply decide(ILoggingEvent event)
{
    FilterReply reply = DENY;
    for(Filter<ILoggingEvent> filter : _filterList)
    {
        FilterReply filterReply = filter.decide(event);
        if (filterReply == DENY)
        {
            reply = filterReply;
            break;
        }
        if (filterReply == ACCEPT)
        {
            reply = filterReply;
        }
    }
    if(reply == ACCEPT)
    {
        switch(event.getLevel().toInt())
        {
            case WARN_INT:
                _warnCount.incrementAndGet();
                break;
            case ERROR_INT:
                _errorCount.incrementAndGet();
                break;
            default:
                // do nothing
        }
        return ACCEPT;
    }
    return DENY;
}
 
Example 2
Source File: PredicateAndLoggerNameAndLevelFilter.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
protected Filter<ILoggingEvent> createFilter(final String loggerName)
{
    final Filter<ILoggingEvent> filter = super.createFilter(loggerName);
    return new Filter<ILoggingEvent>()
    {
        @Override
        public FilterReply decide(final ILoggingEvent event)
        {
            final FilterReply result = filter.decide(event);
            if (result == FilterReply.ACCEPT)
            {
                if (_predicate.evaluate(event))
                {
                    return FilterReply.ACCEPT;
                }
                else
                {
                    return FilterReply.NEUTRAL;
                }
            }
            else
            {
                return result;
            }
        }
    };
}
 
Example 3
Source File: LoggerThresholdFilterTest.java    From logging-java with Apache License 2.0 4 votes vote down vote up
@Test
public void filterSpotifyAtInfoOthersAtWarn() {
    List<Filter<ILoggingEvent>> filters = new ArrayList<Filter<ILoggingEvent>>();

    LoggerThresholdFilter filter = new LoggerThresholdFilter();
    filter.setLogger(spotifyLog);
    filter.setLevel(INFO);
    filter.start();
    filters.add(filter);

    filter = new LoggerThresholdFilter();
    filter.setExceptLogger(spotifyLog);
    filter.setLevel(WARN);
    filter.start();
    filters.add(filter);

    for(Level level : allLevels) {
        final LoggingEvent evt = new LoggingEvent();
        evt.setLevel(level);

        for(String logger : variousLoggers) {
            evt.setLoggerName(logger);

            FilterReply expected;
            FilterReply actual = FilterReply.NEUTRAL;

            if(spotifyLoggers.contains(logger)) {
                if(level.isGreaterOrEqual(INFO))
                    expected = FilterReply.NEUTRAL;
                else
                    expected = FilterReply.DENY;
            } else {
                if(level.isGreaterOrEqual(WARN))
                    expected = FilterReply.NEUTRAL;
                else
                    expected = FilterReply.DENY;
            }

            for(Filter<ILoggingEvent> logFilter : filters) {
                FilterReply nextReply = logFilter.decide(evt);
                actual = andFilterReplies(actual, nextReply);
            }

            assertEquals(String.format("Logger: %s, Level: %s", logger, level.toString()), expected, actual);
        }
    }
}