Coverage for presidio_analyzer / app_tracer.py: 75%
8 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-03-29 09:03 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-03-29 09:03 +0000
1import logging
4class AppTracer:
5 """
6 Allow logging/tracing the system's decisions.
8 Relevant in cases where we want to know which modules were used for detection,
9 which logic was utilized, what results were given and potentially why.
10 This can be useful for analyzing the detection accuracy of the system.
11 :param enabled: Whether tracing should be activated.
12 """
14 def __init__(self, enabled: bool = True):
15 self.logger = logging.getLogger("decision_process")
16 self.enabled = enabled
18 def trace(self, request_id: str, trace_data: str) -> None:
19 """
20 Write a value associated with a decision for a specific request into the trace.
22 Tracing for further inspection if needed.
23 :param request_id: A unique ID, to correlate across calls.
24 :param trace_data: A string to write to the log.
25 """
26 if self.enabled:
27 self.logger.info("[%s][%s]", request_id, trace_data)