Skip to content

Commit

Permalink
fix: 修复windows下日志写入的编码问题 (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaucePlum committed May 31, 2022
1 parent a99b5c5 commit 9ccb4c6
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions botpy/logging.py
Expand Up @@ -2,6 +2,7 @@

import logging
import os
import platform
import sys
from logging.handlers import TimedRotatingFileHandler

Expand Down Expand Up @@ -70,14 +71,15 @@ def get_logger(name=None):
name = "botpy"
log_file = log_path % {"name": name}
file_handler = None
# do not use RotatingFileHandler under Windows
# due to multi-process issue
# save last 7 days log
file_handler = TimedRotatingFileHandler(
filename=log_file,
when="D",
backupCount=7,
)
if platform.system().lower() != "windows":
# save last 7 days log
file_handler = TimedRotatingFileHandler(
filename=log_file,
when="D",
backupCount=7,
)
else:
file_handler = logging.FileHandler(log_file, encoding="utf-8")
if len(logger.handlers) == 0:
file_handler.setLevel(level=logging.DEBUG)
file_handler.setFormatter(formatter)
Expand Down

0 comments on commit 9ccb4c6

Please sign in to comment.