logging error with RotatingFileHandler

flupke flupke at nonexistingdomain.com
Sun Jun 25 04:54:18 EDT 2006


Hi,


i'm getting errors with the log module concerning RotatingFileHandler.
I'm using Python 2.4.3 on Windows XP SP2. This used to work in previous
python versions but since i upgraded to 2.4.3 i get these errors:

Traceback (most recent call last):
  File "C:\Python24\lib\logging\handlers.py", line 71, in emit
    if self.shouldRollover(record):
  File "C:\Python24\lib\logging\handlers.py", line 150, in shouldRollover
    self.stream.seek(0, 2)  #due to non-posix-compliant Windows feature
ValueError: I/O operation on closed file
2006-06-25 10:35:07,171 INFO firebird 210 Starting up the database
Traceback (most recent call last):
  File "C:\Python24\lib\logging\handlers.py", line 72, in emit
    self.doRollover()
  File "C:\Python24\lib\logging\handlers.py", line 134, in doRollover
    self.handleError(record)
NameError: global name 'record' is not defined

I use the logging module by loading a config file:
    import logging
    import logging.config
    LOGFILE = r"logconf.ini"
Then in the init function of the class
    # load logger
    logging.config.fileConfig(LOGFILE)
    self.log = logging.getLogger('stats')

If i have a main class and a class deriving from it, i let the main
class instantiate the class by issueing the commands like above and then
get automatically get access to it in the deriving classes.

If i remove the logfile, it all works until it has to rollover.

My config.ini file contains this info:

[loggers]
keys=root,stats,database

[handlers]
keys=hand01,hand02

[formatters]
keys=form01,form02

[logger_root]
level=NOTSET
handlers=hand01
qualname=(root) # note - this is used in non-root loggers
propagate=1 # note - this is used in non-root loggers
channel=
parent=

[logger_stats]
level=DEBUG
propagate=0
qualname=stats
handlers=hand01,hand02
channel=log02
parent=(root)

[logger_database]
level=DEBUG
propagate=0
qualname=database
handlers=hand01,hand02
channel=log03
parent=(root2

[handler_hand01]
class=StreamHandler
level=DEBUG
formatter=form01
args=(sys.stdout,)
stream=sys.stdout

[handler_hand02]
class=handlers.RotatingFileHandler
level=NOTSET
formatter=form01
filename=stats.log
mode=a
maxsize=500000
backcount=9
args=('stats.log', 'a', 900000, 5)

[formatter_form01]
format=%(asctime)s %(levelname)s %(module)s %(lineno)d %(message)s
datefmt=

[formatter_form02]
format=%(asctime)s %(levelname)s %(module)s %(lineno)d %(message)s
datefmt=

Any idea on why this suddenly doesn't work anymore?
Thanks



More information about the Python-list mailing list