Search in sources :

Example 6 with ListAppender

use of ch.qos.logback.core.read.ListAppender 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

ListAppender (ch.qos.logback.core.read.ListAppender)6 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 Logger (ch.qos.logback.classic.Logger)1 Appender (ch.qos.logback.core.Appender)1 Context (ch.qos.logback.core.Context)1 FilterReply (ch.qos.logback.core.spi.FilterReply)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)1 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)1 StandardResourceClaimManager (org.apache.nifi.controller.repository.claim.StandardResourceClaimManager)1 NiFiProperties (org.apache.nifi.util.NiFiProperties)1 TaskExecutorImpl (org.apache.qpid.server.configuration.updater.TaskExecutorImpl)1 EventLogger (org.apache.qpid.server.logging.EventLogger)1 AbstractBrokerLogger (org.apache.qpid.server.logging.logback.AbstractBrokerLogger)1 Broker (org.apache.qpid.server.model.Broker)1 BrokerModel (org.apache.qpid.server.model.BrokerModel)1 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)1 Model (org.apache.qpid.server.model.Model)1