Change the formatter of the logger handlers.
PARAMETER | DESCRIPTION |
logger | TYPE: Logger |
fmt | The format string for the formatter. TYPE: str |
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
"""
for handler in getattr(logger, "handlers", ()):
formatter = handler.formatter
if formatter is not None: # pragma: no branch
use_colors = getattr(formatter, "use_colors", None)
kwargs = (
{"use_colors": use_colors} if use_colors is not None else {}
) # pragma: no branch
handler.setFormatter(type(formatter)(fmt, **kwargs))
|