[ python-Bugs-939836 ] Logging failes for rotating file log (during rollOver)

SourceForge.net noreply at sourceforge.net
Thu Apr 29 04:55:29 EDT 2004


Bugs item #939836, was opened at 2004-04-22 07:25
Message generated for change (Comment added) made by smeyers2002
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=939836&group_id=5470

Category: Python Library
Group: Python 2.3
>Status: Closed
Resolution: None
Priority: 5
Submitted By: smeyers2002 (smeyers2002)
Assigned to: Vinay Sajip (vsajip)
Summary: Logging failes for rotating file log (during rollOver)

Initial Comment:
I have a problem with the python logging. The attached 
python file 'log.py' initializes the python logging (rotating 
log file) and starts writing lines in a log file.

Everything works, if the line 'log.refresh' is commented 
out. If the line is not commented out, I always get an 
error by the first rollOver. So each time when I re-
initialize the logging (=method refresh in my code) I get 
this error (see below). What can be the problem? 
OS information: Windows XP Professional, version 
5.1.2600 Service Pack 1

Traceback (most recent call last):
  File "log.py", line 21, in ?
    log.logger.info(" I am line "+str(i))
  File "C:\Python23\lib\logging\__init__.py", line 893, in 
info
    apply(self._log, (INFO, msg, args), kwargs)
  File "C:\Python23\lib\logging\__init__.py", line 994, in 
_log
    self.handle(record)
  File "C:\Python23\lib\logging\__init__.py", line 1004, in 
handle
    self.callHandlers(record)
  File "C:\Python23\lib\logging\__init__.py", line 1037, in 
callHandlers
    hdlr.handle(record)
  File "C:\Python23\lib\logging\__init__.py", line 592, in 
handle
    self.emit(record)
  File "C:\Python23\lib\logging\handlers.py", line 105, in 
emit
    self.doRollover()
  File "C:\Python23\lib\logging\handlers.py", line 90, in 
doRollover
    os.rename(self.baseFilename, dfn)
OSError: [Errno 13] Permission denied
--------------------------------
PS: Sometimes I also get the error 'ValueError: I/O 
operation on closed file'

----------------------------------------------------------------------

>Comment By: smeyers2002 (smeyers2002)
Date: 2004-04-29 08:55

Message:
Logged In: YES 
user_id=1026630

Thanks Tim, this solved the problem.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2004-04-22 21:51

Message:
Logged In: YES 
user_id=31435

Windows is unique in that it will not allow renaming (or 
deleting) a file that's open.  I expect that by calling refresh() 
all the time, you're creating additional new objects that have 
C:\log.txt open, so that it's impossible for rollover to rename 
C:\log.txt on Windows.  There's nothing the logging package 
can do about that.

You're also adding an endless number of redundant handlers 
to the same logger.  Try this:

1.  In your __init__ method, set

     self.logger = None

2. Start your refresh() method with

        if self.logger is not None:
            self.rotatingFileLogHandler.close()
            self.logger.removeHandler(self.rotatingFileLogHandler)

Closing the old handler arranges to close the C:\log.txt file, so 
that it's *possible* to rename it on Windows.  Removing the 
old handler from the logger should prevent seeing an 
unpredictable number of copies of individual log msgs, and 
probably prevent some "I/O operation on closed file" screwups 
too.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=939836&group_id=5470



More information about the Python-bugs-list mailing list