public static List<String> findLogMessagesContaining(Level level, String substring) {
    return EVENTS.stream()
        .filter(event -> event.getLevel() == level)
        .map(LogEvent::getMessage)
        .map(Message::getFormattedMessage)
        .filter(msg -> msg.contains(substring))
        .collect(Collectors.toList());
  }
A log appender which captures the log events. This is useful for testing if log events
are being logged correctly and at correct levels.
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/testutils/CapturingLogAppender.java