Skip to content

change_logger_handlers

faststream.broker.utils.change_logger_handlers #

change_logger_handlers(
    logger: logging.Logger, fmt: str
) -> None

Change the formatter of the logger handlers.

PARAMETER DESCRIPTION
logger

The logger object.

TYPE: Logger

fmt

The format string for the formatter.

TYPE: str

RETURNS DESCRIPTION
None

None

Note

The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)

Source code in faststream/broker/utils.py
def change_logger_handlers(logger: logging.Logger, fmt: str) -> None:
    """Change the formatter of the logger handlers.

    Args:
        logger (logging.Logger): The logger object.
        fmt (str): The format string for the formatter.

    Returns:
        None
    !!! note

        The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
    """
    for handler in getattr(logger, "handlers", ()):
        formatter = handler.formatter
        if formatter is not None:  # pragma: no branch
            use_colors = getattr(formatter, "use_colors", None)
            if use_colors is not None:  # pragma: no branch
                kwargs = {"use_colors": use_colors}
            else:  # pragma: no cover
                kwargs = {}
            handler.setFormatter(type(formatter)(fmt, **kwargs))

Last update: 2023-11-13