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));
}
Aggregations