|
15 | 15 |
|
16 | 16 | import java.util.ArrayList;
|
17 | 17 | import java.util.List;
|
| 18 | +import java.util.logging.Level; |
18 | 19 | import java.util.logging.LogRecord;
|
19 | 20 |
|
20 | 21 | import org.apiguardian.api.API;
|
@@ -78,4 +79,35 @@ public List<LogRecord> getLogRecords(Class<?> clazz) {
|
78 | 79 | // @formatter:on
|
79 | 80 | }
|
80 | 81 |
|
| 82 | + /** |
| 83 | + * Get the list of {@link LogRecord log records} that have been |
| 84 | + * {@linkplain #logRecordSubmitted submitted} to this listener |
| 85 | + * for the given class at the given log level. |
| 86 | + * |
| 87 | + * <p>As stated in the JavaDoc for {@code LogRecord}, a submitted |
| 88 | + * {@code LogRecord} should not be updated by the client application. Thus, |
| 89 | + * the {@code LogRecords} in the returned list should only be inspected for |
| 90 | + * testing purposes and not modified in any way. |
| 91 | + * |
| 92 | + * @param clazz the class for which to get the log records; never {@code null} |
| 93 | + * @param level the log level for which to get the log records; never {@code null} |
| 94 | + */ |
| 95 | + public List<LogRecord> getLogRecords(Class<?> clazz, Level level) { |
| 96 | + // NOTE: we cannot use org.junit.platform.commons.util.Preconditions here |
| 97 | + // since that would introduce a package cycle. |
| 98 | + if (clazz == null) { |
| 99 | + throw new JUnitException("Class must not be null"); |
| 100 | + } |
| 101 | + if (level == null) { |
| 102 | + throw new JUnitException("Level must not be null"); |
| 103 | + } |
| 104 | + |
| 105 | + // @formatter:off |
| 106 | + return this.logRecords.stream() |
| 107 | + .filter(logRecord -> logRecord.getLoggerName().equals(clazz.getName())) |
| 108 | + .filter(logRecord -> logRecord.getLevel() == level) |
| 109 | + .collect(toList()); |
| 110 | + // @formatter:on |
| 111 | + } |
| 112 | + |
81 | 113 | }
|
0 commit comments