shouldDebounce static method
Check if a log should be debounced based on time interval
@paramkey: The debounce key to identify the log entry
@paramdebounceMs: Debounce interval in milliseconds
@return: Returns true if the log should be skipped (still in debounce period), false to allow logging
This prevents rapid-fire logging of the same message by enforcing a minimum time interval between consecutive logs with the same key
Implementation
static bool shouldDebounce(String key, int debounceMs) {
if (debounceMs <= 0) return false;
final now = DateTime.now();
final lastTime = _debounceTimestamps[key];
if (lastTime == null) {
_debounceTimestamps[key] = now;
return false;
}
final difference = now.difference(lastTime).inMilliseconds;
if (difference < debounceMs) {
return true; // Still in debounce period, skip this log
}
// Update timestamp and allow log
_debounceTimestamps[key] = now;
return false;
}