为什么我的TimedRotatingFileHandler在午夜不旋转? [英] Why doesn't my TimedRotatingFileHandler rotate at midnight?

查看:513
本文介绍了为什么我的TimedRotatingFileHandler在午夜不旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的配置文件:

[loggers]
keys=root

[handlers]
keys=TimedRotatingFileHandler

[formatters]
keys=simpleFormatter

[logger_root]
level=DEBUG
handlers=TimedRotatingFileHandler

[handler_TimedRotatingFileHandler]
class=handlers.TimedRotatingFileHandler
level=DEBUG
formatter=simpleFormatter
args=('driver.log', 'midnight', 1, 30)

[formatter_simpleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=

在我的代码中,我像这样设置和使用记录器:

In my code I setup and use the logger like this:

import logging
import logging.config

logging.config.fileConfig('logging.conf')
logging.info('Some message...')

消息被记录到我指定的文件(driver.log)中,但是从未发生过午夜的轮换.

Messages are logged to the file I specify (driver.log), but the rotations at midnight never happen.

该流程是否必须在午夜运行才能发生轮换?这是一个批处理过程,我每15分钟运行一次,实际上从未在午夜运行.

Must the process be running at midnight for the rotation to occur? This is a batch process that I run every 15 minutes and it is never actually running at midnight.

推荐答案

答案是,该进程必须一直在运行,才能正常运行.

The answer is that the process must be running all the time for this to work properly.

来自 http://bytes.com/topic/python /answers/595931-timedrotatingfilehandler-isnt-rotating-midnight :

当 日志记录过程创建处理程序 在午夜之前进行伐木 之后发往该处理程序的呼叫 午夜.

Rotating should happen when the logging process creates the handler before midnight and makes a logging call destined for that handler after midnight.

这篇关于为什么我的TimedRotatingFileHandler在午夜不旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆