From 0ae78a4230ca46b0a3f0d922e8e5358cf2de2d66 Mon Sep 17 00:00:00 2001 From: ChenXr <95163115+warr99@users.noreply.github.com> Date: Wed, 14 Aug 2024 20:43:39 +0800 Subject: [PATCH] feat(log): add error level log in logSuppressor (#1799) --- .../com/automq/stream/utils/LogSuppressor.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 (; ; ) {