美文网首页
flask_schedule logging 多进程 问题

flask_schedule logging 多进程 问题

作者: 冰_Angus | 来源:发表于2018-12-19 14:41 被阅读0次

logging模块多进程解决方案
concurrent-log-handler 0.9.12

错误日志

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

解决

  • bash
pip install concurrent-log-handler
pip install pypiwin32
  • 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")

  • 如果有很多日志 建议多弄几个logger
其他参考

flask+schedule+开发环境&生产环境自动切换
Run subprocess and print output to logging

相关文章

网友评论

      本文标题:flask_schedule logging 多进程 问题

      本文链接:https://www.haomeiwen.com/subject/tobqkqtx.html