Files
yidaima_tools/utils/logger.py

19 lines
523 B
Python
Raw Normal View History

2026-04-09 14:55:54 +08:00
from __future__ import annotations
import logging
from typing import Optional
def setup_logging(level: int = logging.INFO, log_file: Optional[str] = None) -> logging.Logger:
handlers: list[logging.Handler] = [logging.StreamHandler()]
if log_file:
handlers.append(logging.FileHandler(log_file, encoding="utf-8"))
logging.basicConfig(
level=level,
format="%(asctime)s | %(levelname)s | %(name)s | %(message)s",
handlers=handlers,
)
return logging.getLogger("yidaima")