[英]Rotating logs using RotatingFileHandler by date in Python
I am looking for a method which will allow me to rotate the logs at midnight instead of rotating them using the maxBytes
parameter. 我正在寻找一种方法,使我可以在午夜旋转日志,而不是使用
maxBytes
参数旋转日志。
So far, the logs are rotated when a file reaches 10MB. 到目前为止,当文件达到10MB时,日志将轮转。
LOG_PATH = os.path.join(APPLICATION_PATH, "log\\My_log.log")
my_handler = RotatingFileHandler(LOG_PATH, mode='a', maxBytes=10000000, backupCount=20)
logger.addHandler(my_handler)
Is there a way of passing a date
parameter to RotatingFileHandler()
so that instead of rotating after the file reaches 10MB it will rotate the file at midnight ? 有没有一种方法可以将
date
参数传递给RotatingFileHandler()
以便在文件达到10MB之后不再旋转,而是在午夜旋转文件?
使用TimedRotatingFileHandler
:
my_handler = TimedRotatingFileHandler(LOG_PATH, when='midnight', backupCount=20)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.