New submission from Eli Courtwright <eli.courtwri...@gmail.com>: 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. ---------- components: Library (Lib) messages: 101242 nosy: Eli.Courtwright severity: normal status: open title: logging.handlers.RotatingFileHandler fails when delay parameter is set to True type: crash versions: Python 2.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue8165> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com