LogContext implements LoggingApi<API>, LogData { @Override public final API atMostEvery(int n, TimeUnit unit) { if (wasForced()) { return api(); } if (n < 0) { throw new IllegalArgumentException("rate limit period cannot be negative"); } if (n > 0) { addMetadata(Key.LOG_AT_MOST_EVERY, LogSiteStats.newRateLimitPeriod(n, unit)); } return api(); } protected  LogContext(Level level, boolean isForced); protected  LogContext(Level level, boolean isForced, long timestampNanos); @Override final Level getLevel(); @Deprecated @Override final long getTimestampMicros(); @Override final long getTimestampNanos(); @Override final String getLoggerName(); @Override final LogSite getLogSite(); @Override final TemplateContext getTemplateContext(); @Override final Object[] getArguments(); @Override final Object getLiteralArgument(); @Override final boolean wasForced(); @Override final Metadata getMetadata(); @Override final API withInjectedLogSite(LogSite logSite); @SuppressWarnings("deprecation") @Override final API withInjectedLogSite(
      String internalClassName,
      String methodName,
      int encodedLineNumber,
      @NullableDecl String sourceFileName); @Override final boolean isEnabled(); @Override final API with(MetadataKey<T> key, @NullableDecl T value); @Override final API with(MetadataKey<Boolean> key); @Override final API withCause(Throwable cause); @Override API withStackTrace(StackSize size); @Override final API every(int n); @Override final API atMostEvery(int n, TimeUnit unit); @Override final void log(); @Override final void log(String msg); @Override final void log(String message, @NullableDecl Object p1); @Override final void log(String message, @NullableDecl Object p1, @NullableDecl Object p2); @Override final void log(
      String message, @NullableDecl Object p1, @NullableDecl Object p2, @NullableDecl Object p3); @Override final void log(
      String message,
      @NullableDecl Object p1,
      @NullableDecl Object p2,
      @NullableDecl Object p3,
      @NullableDecl Object p4); @Override final void log(
      String msg,
      @NullableDecl Object p1,
      @NullableDecl Object p2,
      @NullableDecl Object p3,
      @NullableDecl Object p4,
      @NullableDecl Object p5); @Override final void log(
      String msg,
      @NullableDecl Object p1,
      @NullableDecl Object p2,
      @NullableDecl Object p3,
      @NullableDecl Object p4,
      @NullableDecl Object p5,
      @NullableDecl Object p6); @Override final void log(
      String msg,
      @NullableDecl Object p1,
      @NullableDecl Object p2,
      @NullableDecl Object p3,
      @NullableDecl Object p4,
      @NullableDecl Object p5,
      @NullableDecl Object p6,
      @NullableDecl Object p7); @Override final void log(
      String msg,
      @NullableDecl Object p1,
      @NullableDecl Object p2,
      @NullableDecl Object p3,
      @NullableDecl Object p4,
      @NullableDecl Object p5,
      @NullableDecl Object p6,
      @NullableDecl Object p7,
      @NullableDecl Object p8); @Override final void log(
      String msg,
      @NullableDecl Object p1,
      @NullableDecl Object p2,
      @NullableDecl Object p3,
      @NullableDecl Object p4,
      @NullableDecl Object p5,
      @NullableDecl Object p6,
      @NullableDecl Object p7,
      @NullableDecl Object p8,
      @NullableDecl Object p9); @Override final void log(
      String msg,
      @NullableDecl Object p1,
      @NullableDecl Object p2,
      @NullableDecl Object p3,
      @NullableDecl Object p4,
      @NullableDecl Object p5,
      @NullableDecl Object p6,
      @NullableDecl Object p7,
      @NullableDecl Object p8,
      @NullableDecl Object p9,
      @NullableDecl Object p10); @Override final void log(
      String msg,
      @NullableDecl Object p1,
      @NullableDecl Object p2,
      @NullableDecl Object p3,
      @NullableDecl Object p4,
      @NullableDecl Object p5,
      @NullableDecl Object p6,
      @NullableDecl Object p7,
      @NullableDecl Object p8,
      @NullableDecl Object p9,
      @NullableDecl Object p10,
      Object... rest); @Override final void log(String message, char p1); @Override final void log(String message, byte p1); @Override final void log(String message, short p1); @Override final void log(String message, int p1); @Override final void log(String message, long p1); @Override final void log(String message, @NullableDecl Object p1, boolean p2); @Override final void log(String message, @NullableDecl Object p1, char p2); @Override final void log(String message, @NullableDecl Object p1, byte p2); @Override final void log(String message, @NullableDecl Object p1, short p2); @Override final void log(String message, @NullableDecl Object p1, int p2); @Override final void log(String message, @NullableDecl Object p1, long p2); @Override final void log(String message, @NullableDecl Object p1, float p2); @Override final void log(String message, @NullableDecl Object p1, double p2); @Override final void log(String message, boolean p1, @NullableDecl Object p2); @Override final void log(String message, char p1, @NullableDecl Object p2); @Override final void log(String message, byte p1, @NullableDecl Object p2); @Override final void log(String message, short p1, @NullableDecl Object p2); @Override final void log(String message, int p1, @NullableDecl Object p2); @Override final void log(String message, long p1, @NullableDecl Object p2); @Override final void log(String message, float p1, @NullableDecl Object p2); @Override final void log(String message, double p1, @NullableDecl Object p2); @Override final void log(String message, boolean p1, boolean p2); @Override final void log(String message, char p1, boolean p2); @Override final void log(String message, byte p1, boolean p2); @Override final void log(String message, short p1, boolean p2); @Override final void log(String message, int p1, boolean p2); @Override final void log(String message, long p1, boolean p2); @Override final void log(String message, float p1, boolean p2); @Override final void log(String message, double p1, boolean p2); @Override final void log(String message, boolean p1, char p2); @Override final void log(String message, char p1, char p2); @Override final void log(String message, byte p1, char p2); @Override final void log(String message, short p1, char p2); @Override final void log(String message, int p1, char p2); @Override final void log(String message, long p1, char p2); @Override final void log(String message, float p1, char p2); @Override final void log(String message, double p1, char p2); @Override final void log(String message, boolean p1, byte p2); @Override final void log(String message, char p1, byte p2); @Override final void log(String message, byte p1, byte p2); @Override final void log(String message, short p1, byte p2); @Override final void log(String message, int p1, byte p2); @Override final void log(String message, long p1, byte p2); @Override final void log(String message, float p1, byte p2); @Override final void log(String message, double p1, byte p2); @Override final void log(String message, boolean p1, short p2); @Override final void log(String message, char p1, short p2); @Override final void log(String message, byte p1, short p2); @Override final void log(String message, short p1, short p2); @Override final void log(String message, int p1, short p2); @Override final void log(String message, long p1, short p2); @Override final void log(String message, float p1, short p2); @Override final void log(String message, double p1, short p2); @Override final void log(String message, boolean p1, int p2); @Override final void log(String message, char p1, int p2); @Override final void log(String message, byte p1, int p2); @Override final void log(String message, short p1, int p2); @Override final void log(String message, int p1, int p2); @Override final void log(String message, long p1, int p2); @Override final void log(String message, float p1, int p2); @Override final void log(String message, double p1, int p2); @Override final void log(String message, boolean p1, long p2); @Override final void log(String message, char p1, long p2); @Override final void log(String message, byte p1, long p2); @Override final void log(String message, short p1, long p2); @Override final void log(String message, int p1, long p2); @Override final void log(String message, long p1, long p2); @Override final void log(String message, float p1, long p2); @Override final void log(String message, double p1, long p2); @Override final void log(String message, boolean p1, float p2); @Override final void log(String message, char p1, float p2); @Override final void log(String message, byte p1, float p2); @Override final void log(String message, short p1, float p2); @Override final void log(String message, int p1, float p2); @Override final void log(String message, long p1, float p2); @Override final void log(String message, float p1, float p2); @Override final void log(String message, double p1, float p2); @Override final void log(String message, boolean p1, double p2); @Override final void log(String message, char p1, double p2); @Override final void log(String message, byte p1, double p2); @Override final void log(String message, short p1, double p2); @Override final void log(String message, int p1, double p2); @Override final void log(String message, long p1, double p2); @Override final void log(String message, float p1, double p2); @Override final void log(String message, double p1, double p2); @Override final void logVarargs(String message, @NullableDecl Object[] params);  }
@Test public void testAtMostEvery() { FakeLoggerBackend backend = new FakeLoggerBackend(); TestLogger logger = TestLogger.create(backend); long startNanos = MILLISECONDS.toNanos(System.currentTimeMillis()); for (int millis = 0, count = 0; millis <= 5000; millis += 600) { long timestampNanos = startNanos + MILLISECONDS.toNanos(millis); logger.at(INFO, timestampNanos).atMostEvery(2, SECONDS).log("Count=%d", count++); } assertThat(backend.getLoggedCount()).isEqualTo(3); backend .assertLogged(0) .metadata() .containsUniqueEntry(Key.LOG_AT_MOST_EVERY, LogSiteStats.newRateLimitPeriod(2, SECONDS)); backend.assertLogged(0).hasArguments(0); backend.assertLogged(1).hasArguments(4); backend.assertLogged(2).hasArguments(8); }