MessageDedupingLogger extends DelegatingLogger { @Override public void log(Level level, String message) { if (Objects.requireNonNull(rateLimiterCache.get(message)).tryAcquire()) { log(new LogRecord(level, message)); } } MessageDedupingLogger(Logger delegate,
                               long maximumSize,
                               double rateLimit); @Override void log(Level level, String message);  }
@Test public void testLogger() { Logger mockLogger = EasyMock.createMock(Logger.class); reset(mockLogger); expect(mockLogger.getName()).andReturn("loggerName").anyTimes(); replay(mockLogger); Logger log = new MessageDedupingLogger(mockLogger, 1000, 0.1); reset(mockLogger); expect(mockLogger.getName()).andReturn("loggerName").anyTimes(); Capture<LogRecord> logs = Capture.newInstance(CaptureType.ALL); mockLogger.log(capture(logs)); expectLastCall().times(4); replay(mockLogger); log.severe("msg1"); log.severe("msg1"); log.warning("msg1"); log.info("msg1"); log.config("msg1"); log.fine("msg1"); log.finer("msg1"); log.finest("msg1"); log.warning("msg2"); log.info("msg3"); log.info("msg3"); log.severe("msg4"); log.info("msg3"); log.info("msg3"); log.severe("msg4"); verify(mockLogger); assertEquals(4, logs.getValues().size()); assertEquals("msg1", logs.getValues().get(0).getMessage()); assertEquals(Level.SEVERE, logs.getValues().get(0).getLevel()); assertEquals("msg2", logs.getValues().get(1).getMessage()); assertEquals(Level.WARNING, logs.getValues().get(1).getLevel()); assertEquals("msg3", logs.getValues().get(2).getMessage()); assertEquals(Level.INFO, logs.getValues().get(2).getLevel()); assertEquals("msg4", logs.getValues().get(3).getMessage()); assertEquals(Level.SEVERE, logs.getValues().get(3).getLevel()); }