Skip to content

jmcore.log_filter

jmcore.log_filter

Loguru filters for privacy-sensitive records.

Attributes

__all__ = ['sensitive_log_filter'] module-attribute

Functions:

sensitive_log_filter(sensitive: bool = False) -> Callable[[Record], bool]

Build a Loguru filter that hides records bound with sensitive=True.

Log calls containing wallet, transaction, or detailed error information opt in with logger.bind(sensitive=True). Standard sinks keep those records hidden unless sensitive logging is enabled. This filter selects whole records; it does not redact message contents or exception variable values.

Source code in jmcore/src/jmcore/log_filter.py
14
15
16
17
18
19
20
21
22
23
24
25
26
def sensitive_log_filter(sensitive: bool = False) -> Callable[[Record], bool]:
    """Build a Loguru filter that hides records bound with ``sensitive=True``.

    Log calls containing wallet, transaction, or detailed error information opt in with
    ``logger.bind(sensitive=True)``. Standard sinks keep those records hidden
    unless sensitive logging is enabled. This filter selects whole records;
    it does not redact message contents or exception variable values.
    """

    def filter_record(record: Record) -> bool:
        return sensitive or not bool(record["extra"].get("sensitive", False))

    return filter_record