Search in sources :

Example 1 with FilterReply

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();
}
Also used : Context(ch.qos.logback.core.Context) ConsoleAppender(ch.qos.logback.core.ConsoleAppender) PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) FilterReply(ch.qos.logback.core.spi.FilterReply) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 2 with FilterReply

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);
}
Also used : CompositeFilter(org.apache.qpid.server.logging.logback.CompositeFilter) FilterReply(ch.qos.logback.core.spi.FilterReply) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 3 with FilterReply

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));
}
Also used : CompositeFilter(org.apache.qpid.server.logging.logback.CompositeFilter) FilterReply(ch.qos.logback.core.spi.FilterReply) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 4 with FilterReply

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());
}
Also used : FilterReply(ch.qos.logback.core.spi.FilterReply) LogbackException(ch.qos.logback.core.LogbackException)

Example 5 with FilterReply

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));
}
Also used : FilterReply(ch.qos.logback.core.spi.FilterReply) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LogbackException(ch.qos.logback.core.LogbackException)

Aggregations

FilterReply (ch.qos.logback.core.spi.FilterReply)21 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)8 LogbackException (ch.qos.logback.core.LogbackException)5 CompositeFilter (org.apache.qpid.server.logging.logback.CompositeFilter)5 Subject (javax.security.auth.Subject)4 VirtualHostPrincipal (org.apache.qpid.server.virtualhost.VirtualHostPrincipal)4 Principal (java.security.Principal)3 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)1 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)1 Context (ch.qos.logback.core.Context)1 ListAppender (ch.qos.logback.core.read.ListAppender)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 EventLogger (org.apache.qpid.server.logging.EventLogger)1 Logger (org.slf4j.Logger)1