Skip to content

Commit a6ec6c9

Browse files
committed
Fix from rebasing
1 parent 6a60f1e commit a6ec6c9

2 files changed

Lines changed: 8 additions & 15 deletions

File tree

src/daqpytools/logging/handlers.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,6 @@ def reset(self):
191191
class BaseHandlerFilter(logging.Filter):
192192
def __init__(self):
193193
super().__init__()
194-
#TODO/ask: See if we want to define this mapping elsewhere
195-
self.level_to_ers_var = {
196-
logging.ERROR: "DUNEDAQ_ERS_ERROR",
197-
logging.WARNING: "DUNEDAQ_ERS_WARNING",
198-
logging.CRITICAL: "DUNEDAQ_ERS_FATAL",
199-
logging.INFO: "DUNEDAQ_ERS_INFO",
200-
}
201194

202195
def get_allowed(self, record) -> list | None:
203196
# TODO/future: kafka protobufs should validate url/port match before transmitting
@@ -206,7 +199,7 @@ def get_allowed(self, record) -> list | None:
206199
if getattr(record, "stream", None) == StreamType.ERS:
207200
# Chain None checks using walrus operator
208201
if (
209-
(ers_level_var := self.level_to_ers_var.get(record.levelno)) is None
202+
(ers_level_var := level_to_ers_var.get(record.levelno)) is None
210203
or (ers_handlers := getattr(record, "ers_handlers", None)) is None
211204
or (ershandlerconf := ers_handlers.get(ers_level_var)) is None
212205
):
@@ -223,10 +216,10 @@ def get_allowed(self, record) -> list | None:
223216
class HandleIDFilter(BaseHandlerFilter):
224217
"""Filter class that accepts a list of 'allowed' handlers and will only fire
225218
if the current handler (defined by the handler_id) is within the set of
226-
allowed handlers
219+
allowed handlers.
227220
"""
228221

229-
def __init__(self, handler_id: Union[HandlerType, List[HandlerType]]):
222+
def __init__(self, handler_id: Union[HandlerType, List[HandlerType]]) -> None:
230223
"""Initialises HandleIDFilter with the handler_id, to identify what
231224
kind of handler this filter is.
232225
"""
@@ -238,7 +231,7 @@ def __init__(self, handler_id: Union[HandlerType, List[HandlerType]]):
238231
else:
239232
self.handler_ids = {handler_id}
240233

241-
def filter(self, record):
234+
def filter(self, record: logging.LogRecord) -> bool:
242235
"""Identifies when a log message should be transmitted or not."""
243236
allowed = self.get_allowed(record)
244237
if not allowed:

src/daqpytools/logging/levels.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ def logging_log_level_to_str(log_level: str | int) -> str:
109109
}
110110

111111
level_to_ers_var = {
112-
"ERROR": "DUNEDAQ_ERS_ERROR",
113-
"WARNING": "DUNEDAQ_ERS_WARNING",
114-
"CRITICAL": "DUNEDAQ_ERS_FATAL",
115-
"INFO": "DUNEDAQ_ERS_INFO",
112+
logging.ERROR: "DUNEDAQ_ERS_ERROR",
113+
logging.WARNING: "DUNEDAQ_ERS_WARNING",
114+
logging.CRITICAL: "DUNEDAQ_ERS_FATAL",
115+
logging.INFO: "DUNEDAQ_ERS_INFO",
116116
}
117117

118118

0 commit comments

Comments
 (0)