19 lines
523 B
Python
19 lines
523 B
Python
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")
|
|
|