Skip to main content
Version: Next

LoggerOnce

Emits each log message at most once, keyed by an explicit string.

Useful for diagnostic warnings that would otherwise spam the log when the same condition recurs (per-request misconfiguration warnings, repeated fallback paths, etc.). Deduplication scope follows the lifetime of the instance — a module-level instance gives process-wide dedup; an attribute on a class gives per-instance dedup.

Index

Methods

__init__

  • __init__(logger): None
  • Parameters

    • logger: logging.Logger

    Returns None

log

  • log(message, *, key, level): None
  • Log message at level the first time key is seen on this instance; later calls are no-ops.


    Parameters

    • message: str

      The message to log.

    • keyword-onlykey: str

      Deduplication key. Two calls with the same key emit at most once.

    • optionalkeyword-onlylevel: int = logging.INFO

      Standard logging level (e.g. logging.WARNING). Defaults to logging.INFO.

    Returns None

Page Options