Skip to content

Audit

Log a message but only log recently repeated messages at intervals.

Source code in nava/platform/cli/logging/audit.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
def log_audit_event(
    logger: Logger, event_name: str, args: Sequence[Any], arg_names: Sequence[str]
) -> None:
    """Log a message but only log recently repeated messages at intervals."""
    extra = {
        f"audit.args.{arg_name}": arg
        for arg_name, arg in zip(arg_names, args, strict=True)
        if arg_name != "_"
    }

    key = (event_name, repr(args))
    if key not in audit_message_count:  # noqa: SIM108
        count = 1
    else:
        count = audit_message_count[key] + 1
    audit_message_count[key] = count

    if count > 100 and count % 100 != 0:
        return

    if count > 10 and count % 10 != 0:
        return

    extra["count"] = count

    logger(event_name, **extra)