File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ """Module for log message filtering, excluding strings & limiting warnings."""
2+
3+ from collections import defaultdict
4+ import time
5+
6+ from openadapt import config
7+
8+ MESSAGE_TIMESTAMPS = defaultdict (list )
9+
10+ # TODO: move utils.configure_logging to here
11+
12+
13+ def filter_log_messages (data : dict ) -> bool :
14+ """Filter log messages based on the defined criteria.
15+
16+ Args:
17+ data: The log message data from a loguru logger.
18+
19+ Returns:
20+ bool: True if the log message should not be ignored, False otherwise.
21+ """
22+ # TODO: ultimately, we want to fix the underlying issues, but for now,
23+ # we can ignore these messages
24+ for msg in config .MESSAGES_TO_FILTER :
25+ if msg in data ["message" ]:
26+ if config .MAX_NUM_WARNINGS_PER_SECOND > 0 :
27+ current_timestamp = time .time ()
28+ MESSAGE_TIMESTAMPS [msg ].append (current_timestamp )
29+ timestamps = MESSAGE_TIMESTAMPS [msg ]
30+
31+ # Remove timestamps older than 1 second
32+ timestamps = [
33+ ts
34+ for ts in timestamps
35+ if current_timestamp - ts <= config .WARNING_SUPPRESSION_PERIOD
36+ ]
37+
38+ if len (timestamps ) > config .MAX_NUM_WARNINGS_PER_SECOND :
39+ return False
40+
41+ MESSAGE_TIMESTAMPS [msg ] = timestamps
42+
43+ return True
You can’t perform that action at this time.
0 commit comments