This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Eli.Courtwright
Recipients Eli.Courtwright
Date 2010-03-17.19:58:07
SpamBayes Score 1.1505241e-12
Marked as misclassified No
Message-id <1268855892.12.0.046452887236.issue8165@psf.upfronthosting.co.za>
In-reply-to
Content
Here's a summary of the issue (also presented at http://stackoverflow.com/questions/2465073)

When I run the following code

{{{
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, the problem completely goes away.

So one of the parent __init__ methods somewhere up the class hierarchy isn't getting called when delay is set. Examining the source code to the file logging/__init__.py, 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.

Unfortunately, I don't have time right now to submit a patch, though I might be able to find the time within the next few months if no one else gets to it first.  Hopefully this report is detailed enough to easily convey the problem.
History
Date User Action Args
2010-03-17 19:58:12Eli.Courtwrightsetrecipients: + Eli.Courtwright
2010-03-17 19:58:12Eli.Courtwrightsetmessageid: <1268855892.12.0.046452887236.issue8165@psf.upfronthosting.co.za>
2010-03-17 19:58:08Eli.Courtwrightlinkissue8165 messages
2010-03-17 19:58:07Eli.Courtwrightcreate