Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RotatingFileHandler throws an exception when delay parameter is set

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!")

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

rfh.setLevel(logging.DEBUG)

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.

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

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

EDIT: 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.

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.

like image 241
Eli Courtwright Avatar asked Sep 15 '26 13:09

Eli Courtwright


1 Answers

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

like image 52
Vinay Sajip Avatar answered Sep 18 '26 02:09

Vinay Sajip



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!