mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-144539 Reduce the amount of log spam by FrequentEventDetector
This commit is contained in:
@@ -18,6 +18,8 @@ package com.intellij.openapi.diagnostic;
|
||||
import com.intellij.util.ExceptionUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
@@ -30,6 +32,12 @@ public class FrequentEventDetector {
|
||||
|
||||
private long myStartedCounting = System.currentTimeMillis();
|
||||
private final AtomicInteger myEventsPosted = new AtomicInteger();
|
||||
private final Map<String, String> myRecentTraces = new LinkedHashMap<String, String>() {
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry<String, String> eldest) {
|
||||
return size() > 5;
|
||||
}
|
||||
};
|
||||
private final int myEventCountThreshold;
|
||||
private final int myTimeSpanMs;
|
||||
private final Level myLevel;
|
||||
@@ -58,7 +66,13 @@ public class FrequentEventDetector {
|
||||
}
|
||||
|
||||
if (shouldLog) {
|
||||
String message = "Too many events posted\n" + ExceptionUtil.getThrowableText(new Throwable());
|
||||
String trace = ExceptionUtil.getThrowableText(new Throwable());
|
||||
boolean logTrace;
|
||||
synchronized (myEventsPosted) {
|
||||
logTrace = myRecentTraces.put(trace, trace) == null;
|
||||
}
|
||||
|
||||
String message = "Too many events posted" + (logTrace ? "\n" + trace : "");
|
||||
if (myLevel == Level.INFO) {
|
||||
LOG.info(message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user