Skip to content

toolr.utils._logs

DuplicateTimesFormatter

DuplicateTimesFormatter(*args: Any, **kwargs: Any)

Bases: Formatter

Formatter that adds a timestamp to the message, if it's not a duplicate.

Source code in python/toolr/utils/_logs.py
def __init__(self, *args: Any, **kwargs: Any) -> None:
    super().__init__(*args, **kwargs)
    self._last_timestamp: str | None = None

include_timestamps

include_timestamps() -> bool

Return True if any of the configured logging handlers includes timestamps.

Source code in python/toolr/utils/_logs.py
def include_timestamps() -> bool:
    """
    Return True if any of the configured logging handlers includes timestamps.
    """
    return any(handler.formatter is TIMESTAMP_FORMATTER for handler in logging.root.handlers)

setup_logging

setup_logging(
    verbosity: ConsoleVerbosity, timestamps: bool = False
) -> None

Setup logging level and logging handler formatter.

Source code in python/toolr/utils/_logs.py
def setup_logging(verbosity: ConsoleVerbosity, timestamps: bool = False) -> None:
    """
    Setup logging level and logging handler formatter.
    """
    match verbosity:
        case ConsoleVerbosity.VERBOSE:
            logging.root.setLevel(logging.DEBUG)
        case ConsoleVerbosity.QUIET:
            logging.root.setLevel(logging.CRITICAL + 1)
        case _:
            logging.root.setLevel(logging.INFO)

    formatter: logging.Formatter
    if timestamps:
        formatter = TIMESTAMP_FORMATTER
    else:
        formatter = NO_TIMESTAMP_FORMATTER
    for handler in logging.root.handlers:
        handler.setFormatter(formatter)