Skip to content

Commit

Permalink
Merge pull request #133 from Starry-OvO/develop
Browse files Browse the repository at this point in the history
fix: re-entry of `enable_filelog`
  • Loading branch information
lumina37 authored Jul 3, 2023
2 parents f62e9e4 + 271523a commit f294916
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions aiotieba/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def set_formatter(formatter: logging.Formatter) -> None:
hd.setFormatter(formatter)


_FILELOG_ENABLED = False


def enable_filelog(log_level: int = logging.INFO, log_dir: Path = Path('log'), backup_count: int = 5) -> None:
"""
启用文件日志
Expand All @@ -91,6 +94,11 @@ def enable_filelog(log_level: int = logging.INFO, log_dir: Path = Path('log'), b
backup_count (int): 时间轮转文件日志的保留文件数. Defaults to 5.
"""

global _FILELOG_ENABLED

if _FILELOG_ENABLED:
return

Path(log_dir).mkdir(0o755, exist_ok=True)

file_hd = logging.handlers.TimedRotatingFileHandler(
Expand All @@ -99,3 +107,5 @@ def enable_filelog(log_level: int = logging.INFO, log_dir: Path = Path('log'), b
file_hd.setLevel(log_level)
file_hd.setFormatter(_FORMATTER)
LOGGER.addHandler(file_hd)

_FILELOG_ENABLED = True

0 comments on commit f294916

Please sign in to comment.