目录

flask_schedule logging 多进程问题

# flask_schedule logging 多进程问题

logging 模块多进程解决方案 (opens new window) concurrent-log-handler 0.9.12 (opens new window)

# 错误日志

PermissionError: [WinError 32] 另一个程序正在使用此文件,进程无法访问。: 'E:\\logs\\contest\\contest.log' -> 'E:\\logs\\contest\\contest.log.1'    
1

# 解决

  • bash
pip install concurrent-log-handler    
pip install pypiwin32    
1
2
  • python
from logging import getLogger, DEBUG    
from concurrent_log_handler import ConcurrentRotatingFileHandler    
import os    
    
logger = getLogger()    
# Use an absolute path to prevent file rotation trouble.    
logfile = os.path.abspath("mylogfile.log")    
# Rotate log after reaching 512K, keep 5 old copies.    
rotateHandler = ConcurrentRotatingFileHandler(logfile, "a", 512*1024, 5)    
logger.addHandler(rotateHandler)    
logger.setLevel(DEBUG)    
    
logger.info("Here is a very exciting log message, just for you")    
    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  • 如果有很多日志 建议多弄几个 logger

# 其他参考

上次更新: 2024-01-10 16:01:00
最近更新
01
自建 RSS 订阅
01-05
02
搭建私人 docker hub
01-02
03
关于 SSH 攻击
10-12
更多文章>