Search in sources :

Example 21 with FilterReply

use of ch.qos.logback.core.spi.FilterReply in project qpid-broker-j by apache.

the class AbstractVirtualHostTest method assertActionProducesLogMessage.

private void assertActionProducesLogMessage(final Runnable action, final String loggerName, final Level logLevel, final String message) throws Exception {
    final CountDownLatch logMessageReceivedLatch = new CountDownLatch(1);
    ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    ListAppender<ILoggingEvent> appender = new ListAppender<>();
    appender.addFilter(new Filter<ILoggingEvent>() {

        @Override
        public FilterReply decide(final ILoggingEvent event) {
            if (event.getLoggerName().equals(loggerName) && event.getLevel().equals(logLevel) && event.getFormattedMessage().contains(message)) {
                logMessageReceivedLatch.countDown();
            }
            return FilterReply.NEUTRAL;
        }
    });
    appender.setContext(rootLogger.getLoggerContext());
    appender.start();
    rootLogger.addAppender(appender);
    action.run();
    assertTrue("Did not receive expected log message", logMessageReceivedLatch.await(2, TimeUnit.SECONDS));
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) CountDownLatch(java.util.concurrent.CountDownLatch) EventLogger(org.apache.qpid.server.logging.EventLogger) Logger(org.slf4j.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) FilterReply(ch.qos.logback.core.spi.FilterReply) ListAppender(ch.qos.logback.core.read.ListAppender)

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