Spaces:
Sleeping
Sleeping
File size: 931 Bytes
300df0f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | """Shared logging helpers for human-friendly console output."""
from __future__ import annotations
import logging
from pathlib import Path
from typing import Optional
from rich.logging import RichHandler
def configure_logging(level: str = "INFO", log_path: Optional[str] = None) -> None:
"""Configure root logging with Rich and an optional file handler."""
handlers: list[logging.Handler] = [
RichHandler(
rich_tracebacks=True,
markup=False,
show_time=False,
show_level=True,
show_path=False,
)
]
if log_path:
path = Path(log_path)
path.parent.mkdir(parents=True, exist_ok=True)
handlers.append(logging.FileHandler(path, encoding="utf-8"))
logging.basicConfig(
level=getattr(logging, level.upper(), logging.INFO),
format="%(message)s",
handlers=handlers,
force=True,
)
|