设置延迟参数时,RotatingFileHandler引发异常 [英] RotatingFileHandler throws an exception when delay parameter is set

查看:161
本文介绍了设置延迟参数时,RotatingFileHandler引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Python 2.6下运行以下代码时

When I run the following code under Python 2.6

import logging
from logging.handlers import RotatingFileHandler

rfh = RotatingFileHandler("testing.log", delay=True)
logging.getLogger().addHandler(rfh)
logging.warning("Boo!")

然后最后一行抛出AttributeError: RotatingFileHandler instance has no attribute 'level'.所以我添加了行

then the last line throws AttributeError: RotatingFileHandler instance has no attribute 'level'. So I add the line

rfh.setLevel(logging.DEBUG)

在调用addHandler之前,然后最后一行引发AttributeError: RotatingFileHandler instance has no attribute 'filters'.因此,如果我手动将过滤器设置为空列表,那么它将抱怨没有属性lock等.

before the call to addHandler, and then the last line throws AttributeError: RotatingFileHandler instance has no attribute 'filters'. So if I manually set filters to be an empty list, then it complains about not having the attribute lock, etc.

当我删除delay=True并将其保留为False的默认值时,如此处记录所示,问题完全消失了.

When I remove the delay=True to leave it as the default value of False as documented here, the problem completely goes away.

我错过了什么吗?如何正确使用RotatingFileHandler类的delay参数?

Am I missing something? How do I properly use the delay parameter of the RotatingFileHandler class?

经过进一步分析(在下面我自己的答案中显示),这看起来像是一个错误,但是我在

Upon further analysis (presented in my own answer below), this looks like a bug, but I can't find a bug report on this in the Python bug tracker, even trying different search terms, so I guess I'll report it.

但是,如果有人可以找到实际的错误报告,那么我可以避免提交重复的报告并浪费Python开发人员的时间.我将延迟几个小时报告该错误,如果有人发布了包含当前错误报告的答案,那么我将接受该问题的答案.

However, if someone can locate the actual bug report, then I can avoid submitting a duplicate reporting and wasting the time of the Python developers. I'll hold off on reporting the bug for a few hours, and if someone posts an answer that has the current bug report, then I'll accept that answer for this question.

推荐答案

我已经研究了此问题:该问题已在2009年1月20日发布的Python SVN r68829中修复.此问题在2.6.1发行之后,但在发行之前2.6.2.

I've investigated this issue: it was fixed in Python SVN r68829 dated 20 Jan, 2009. This was after the release of 2.6.1 but before the release of 2.6.2.

请升级到Python 2.6.2或更高版本.

Please upgrade to Python 2.6.2, or a later version.

我已经更新了您提交的错误.顺便说一句,提交的原始错误报告是#5013 ,您可以通过搜索所有问题(不仅仅是打开问题)来找到")(例如(摘自此页面).

I've updated the bug you filed. BTW the original bug report filed was #5013, which you could have found by searching all issues (not just open ones) for RotatingFileHandler, like this (from this page).

这篇关于设置延迟参数时,RotatingFileHandler引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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