RotatingFileHandler throws an exception when delay parameter is set

好久不见. 提交于 2019-12-06 01:41:00

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.

Please upgrade to Python 2.6.2, or a later version.

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).

I think I've just figured this out:

So it looks like one of the parent __init__ methods somewhere up the class hierarchy isn't getting called when delay is set. Indeed, examining the source code to the file logging/__init__.py in my Python install, I see the following code in the FileHandler.__init__ method:

if delay:
    self.stream = None
else:
    stream = self._open()
    StreamHandler.__init__(self, stream)

It looks like the FileHandler.emit method checks for un-opened streams and finishes initialization when logging is performed:

if self.stream is None:
    stream = self._open()
    StreamHandler.__init__(self, stream)
StreamHandler.emit(self, record)

So the problem is that in the BaseRotatingHandler.emit method, the shouldRollover and doRollover methods are called before emit-ing the record. This causes methods to be called which themselves assumed that the __init__ process has completed.

This looks like a bug, so I'll report it as such if I can't find it having been already been reported.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!