New submission from Christophe Kalt <k...@taranis.org>:

logging.RotatingFileHandler.doRollover() can fail leaving the handler with a 
closed filehandle, causing all subsequent logging attempts to fail:

>>> import logging
>>> import logging.handlers
>>> logging.getLogger().addHandler(logging.handlers.RotatingFileHandler('testlog',
>>>  None, 10, 5))
>>> logging.getLogger().setLevel(logging.INFO)
>>> logging.info('qwertyuiop')
>>> os.system('ls -l testlog*')
-rw-r--r-- 1 - - 11 Jan 19 10:02 testlog
-rw-r--r-- 1 - -  0 Jan 19 10:02 testlog.1
0
>>> os.remove('testlog')
>>> logging.info('qwertyuiop')
Traceback (most recent call last):
  File "/home8/taraniso/opt/lib/python2.6/logging/handlers.py", line 72, in emit
    self.doRollover()
  File "/home8/taraniso/opt/lib/python2.6/logging/handlers.py", line 129, in 
doRollover
    os.rename(self.baseFilename, dfn)
OSError: [Errno 2] No such file or directory
>>> logging.info('qwertyuiop')
Traceback (most recent call last):
  File "/home8/taraniso/opt/lib/python2.6/logging/handlers.py", line 71, in emit
    if self.shouldRollover(record):
  File "/home8/taraniso/opt/lib/python2.6/logging/handlers.py", line 145, in 
shouldRollover
    self.stream.seek(0, 2)  #due to non-posix-compliant Windows feature
ValueError: I/O operation on closed file
>>> logging.info('qwertyuiop')
Traceback (most recent call last):
  File "/home8/taraniso/opt/lib/python2.6/logging/handlers.py", line 71, in emit
    if self.shouldRollover(record):
  File "/home8/taraniso/opt/lib/python2.6/logging/handlers.py", line 145, in 
shouldRollover
    self.stream.seek(0, 2)  #due to non-posix-compliant Windows feature
ValueError: I/O operation on closed file

Fix seems trivial enough, attaching.  This is against 2.6.5, browsing 
subversion online seems to indicate it is needed on the trunk as well, although 
it won't apply cleanly.

----------
components: Library (Lib)
files: logging.diff
keywords: patch
messages: 126541
nosy: kalt
priority: normal
severity: normal
status: open
title: logging.RotatingFileHandler not robust enough
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1
Added file: http://bugs.python.org/file20454/logging.diff

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10949>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to