init
This commit is contained in:
18
utils/logger.py
Normal file
18
utils/logger.py
Normal file
@@ -0,0 +1,18 @@
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user