Skip to content

Commit 596f07d

Browse files
authored
Avoid flooding the logger with ~500 errors when they are the same (hardbyte#1125)
Only log/warn each unique error once with repeat count, when needed. Adding dot to separate end the short description sentence before the long description.
1 parent 1979a75 commit 596f07d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

can/interfaces/ics_neovi/neovi_bus.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import logging
1212
import os
1313
import tempfile
14-
from collections import deque, defaultdict
14+
from collections import deque, defaultdict, Counter
1515
from itertools import cycle
1616
from threading import Event
1717
from warnings import warn
@@ -89,7 +89,7 @@ def __init__(
8989
severity: int,
9090
restart_needed: int,
9191
):
92-
super().__init__(f"{description_short} {description_long}", error_code)
92+
super().__init__(f"{description_short}. {description_long}", error_code)
9393
self.description_short = description_short
9494
self.description_long = description_long
9595
self.severity = severity
@@ -319,9 +319,12 @@ def _process_msg_queue(self, timeout=0.1):
319319
if errors:
320320
logger.warning("%d error(s) found", errors)
321321

322-
for msg in ics.get_error_messages(self.dev):
323-
error = ICSOperationError(*msg)
324-
logger.warning(error)
322+
for msg, count in Counter(ics.get_error_messages(self.dev)).items():
323+
error = ICSApiError(*msg)
324+
if count > 1:
325+
logger.warning(f"{error} (Repeated {count} times)")
326+
else:
327+
logger.warning(error)
325328

326329
def _get_timestamp_for_msg(self, ics_msg):
327330
if self._use_system_timestamp:

0 commit comments

Comments
 (0)