Skip to content

Commit

Permalink
feat(log): add error level log in logSuppressor (#1799)
Browse files Browse the repository at this point in the history
  • Loading branch information
warr99 authored Aug 14, 2024
1 parent 9ee6cfe commit 0ae78a4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions s3stream/src/main/java/com/automq/stream/utils/LogSuppressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 (; ; ) {
Expand Down

0 comments on commit 0ae78a4

Please sign in to comment.