Files
resume/resume/utils/logging.py
Pavel Sobolev d5ff05abdb add linters
2025-11-13 01:33:00 +03:00

36 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Утилиты логирования с интеграцией RichHandler.
Предоставляет помощник для настройки корневого логгера на базе стандартного
модуля logging и `rich.logging.RichHandler` для улучшенной читаемости вывода
и наглядных трассировок исключений.
В модуле приняты:
- Формат: "%(asctime)s [%(levelname)s] %(message)s"
- Уровень: INFO по умолчанию
"""
import logging
from rich.logging import RichHandler
def configure_root_logger(
level: int = logging.INFO, datefmt: str | None = "%H:%M:%S"
) -> logging.Logger:
"""Настроить корневой логгер с RichHandler и вернуть корневой логгер.
Args:
level (int): Уровень логирования (например, logging.INFO).
datefmt (Optional[str]): Формат времени для меток времени.
Returns:
logging.Logger: Настроенный корневой логгер.
"""
logging.basicConfig(
level=level,
format="%(asctime)s [%(levelname)s] %(message)s",
datefmt=datefmt,
handlers=[RichHandler(rich_tracebacks=True, show_time=False)],
)
return logging.getLogger()