小编Vin*_*yak的帖子

在 TimedRotatingFileHandler 中添加文件扩展名

我正在尝试使用TimedRotatingFileHandler实现 python 日志记录

我在日志文件名中添加文件扩展名时遇到问题

这是我的代码

Path(".\\Log").mkdir(parents=True, exist_ok=True)
LOGGING_MSG_FORMAT  = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
LOGGING_DATE_FORMAT = '%m-%d %H:%M:%S'
formatter = logging.Formatter(LOGGING_MSG_FORMAT, LOGGING_DATE_FORMAT)
handler = TimedRotatingFileHandler(".\\Log\\info.log",'midnight',1)
handler.setFormatter(formatter)
handler.setLevel(logging.INFO)
root_logger = logging.getLogger()
root_logger.addHandler(handler)
Run Code Online (Sandbox Code Playgroud)

第一次使用此代码时,我按预期获得文件名“info.log”,但是当它滚动到午夜时,我得到的文件名是“info.log.2020-05-22”,但我是什么期待的是“info.2020-05-22.log”。

我如何将处理程序后缀附加到文件扩展名(.log)之前?

python python-logging

5
推荐指数
1
解决办法
1788
查看次数

标签 统计

python ×1

python-logging ×1