diff --git a/s3stream/src/main/java/com/automq/stream/utils/LogSuppressor.java b/s3stream/src/main/java/com/automq/stream/utils/LogSuppressor.java index 4360d32980..65b9cbfed0 100644 --- a/s3stream/src/main/java/com/automq/stream/utils/LogSuppressor.java +++ b/s3stream/src/main/java/com/automq/stream/utils/LogSuppressor.java @@ -26,6 +26,22 @@ public LogSuppressor(Logger logger, long intervalMills) { this.intervalMills = intervalMills; } + public void error(String message, Object... args) { + long now = System.currentTimeMillis(); + for (; ; ) { + long last = lastLogTime.get(); + if (now - last > intervalMills) { + if (lastLogTime.compareAndSet(last, now)) { + logger.error("[SUPPRESSED_TIME=" + suppressedCount.getAndSet(0) + "] " + message, args); + break; + } + } else { + suppressedCount.incrementAndGet(); + break; + } + } + } + public void warn(String message, Object... args) { long now = System.currentTimeMillis(); for (; ; ) {