RecentLogFilter implements Filter { public boolean isLoggable(LogRecord record) { String msg = record.getMessage(); if (msg != null && recent.contains(msg)) { return false; } else { recent.addLast(msg); if (recent.size() > maxMessages) { recent.removeFirst(); } return true; } }  boolean isLoggable(LogRecord record);  }
@Test public void basic() { RecentLogFilter rlf = new RecentLogFilter(); List<LogRecord> logRecords = new ArrayList<>(); for (int i = 0; i < RecentLogFilter.maxMessages + 1; i++) { logRecords.add(new LogRecord(Level.INFO, "" + i)); } assertTrue(rlf.isLoggable(logRecords.get(0))); assertFalse(rlf.isLoggable(logRecords.get(0))); for (int i = 1; i < RecentLogFilter.maxMessages + 1; i++) { assertTrue(rlf.isLoggable(logRecords.get(i))); } assertTrue(rlf.isLoggable(logRecords.get(0))); }