use of ch.qos.logback.core.spi.FilterReply in project qpid-broker-j by apache.
the class StartupAppender method logToConsole.
public void logToConsole() {
Context context = getContext();
ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>();
consoleAppender.setContext(context);
PatternLayoutEncoder patternLayoutEncoder = new PatternLayoutEncoder();
patternLayoutEncoder.setContext(context);
// added MDC variable 'qpid.log.prefix' for test purposes
patternLayoutEncoder.setPattern("%X{qpid.log.prefix}%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n");
patternLayoutEncoder.start();
consoleAppender.addFilter(new Filter<ILoggingEvent>() {
@Override
public FilterReply decide(final ILoggingEvent event) {
return event.getLevel().isGreaterOrEqual(_consoleAppenderAcceptLogLevel) ? FilterReply.ACCEPT : FilterReply.DENY;
}
});
consoleAppender.setEncoder(patternLayoutEncoder);
consoleAppender.start();
replayAccumulatedEvents(consoleAppender);
consoleAppender.stop();
}
use of ch.qos.logback.core.spi.FilterReply in project qpid-broker-j by apache.
the class CompositeFilterTest method testDecideWithAcceptRule.
public void testDecideWithAcceptRule() {
CompositeFilter compositeFilter = new CompositeFilter();
compositeFilter.addLogInclusionRule(createRule(FilterReply.ACCEPT));
final ILoggingEvent loggingEvent = mock(ILoggingEvent.class);
when(loggingEvent.getLevel()).thenReturn(Level.ERROR);
FilterReply reply = compositeFilter.decide(loggingEvent);
assertEquals("Unexpected reply with ACCEPT rule added", FilterReply.ACCEPT, reply);
}
use of ch.qos.logback.core.spi.FilterReply in project qpid-broker-j by apache.
the class CompositeFilterTest method testRemoveLogInclusionRule.
public void testRemoveLogInclusionRule() {
CompositeFilter compositeFilter = new CompositeFilter();
LogBackLogInclusionRule neutral = createRule(FilterReply.NEUTRAL, "neutral");
compositeFilter.addLogInclusionRule(neutral);
LogBackLogInclusionRule deny = createRule(FilterReply.DENY, "deny");
compositeFilter.addLogInclusionRule(deny);
LogBackLogInclusionRule accept = createRule(FilterReply.ACCEPT, "accept");
compositeFilter.addLogInclusionRule(accept);
FilterReply reply = compositeFilter.decide(mock(ILoggingEvent.class));
assertEquals("Unexpected reply", FilterReply.DENY, reply);
compositeFilter.removeLogInclusionRule(deny);
final ILoggingEvent loggingEvent = mock(ILoggingEvent.class);
when(loggingEvent.getLevel()).thenReturn(Level.ERROR);
FilterReply reply2 = compositeFilter.decide(loggingEvent);
assertEquals("Unexpected reply", FilterReply.ACCEPT, reply2);
verify(neutral.asFilter(), times(2)).decide(any(ILoggingEvent.class));
verify(deny.asFilter()).decide(any(ILoggingEvent.class));
verify(accept.asFilter()).decide(any(ILoggingEvent.class));
}
use of ch.qos.logback.core.spi.FilterReply in project qpid-broker-j by apache.
the class Logback1027WorkaroundTurboFilterTest method testNoRecursion2.
public void testNoRecursion2() {
Exception e1 = new Exception();
Exception e2 = new Exception();
Exception e3 = new Exception();
e2.initCause(e3);
e1.initCause(e2);
e1.addSuppressed(e3);
final FilterReply reply = doDecide(e1);
assertEquals(FilterReply.NEUTRAL, reply);
assertEquals(0, _snoopingAppender.getEvents().size());
}
use of ch.qos.logback.core.spi.FilterReply in project qpid-broker-j by apache.
the class Logback1027WorkaroundTurboFilterTest method testSuppressedExceptionRecursion.
public void testSuppressedExceptionRecursion() {
Exception e1 = new Exception();
Exception e2 = new Exception();
e2.addSuppressed(e1);
e1.addSuppressed(e2);
final FilterReply reply = doDecide(e1);
assertEquals(FilterReply.DENY, reply);
final List<ILoggingEvent> events = _snoopingAppender.getEvents();
assertEquals(1, events.size());
assertLoggingEvent(events.get(0));
}
Aggregations