Reputation: 341
I could use this code below on Python 2. I tried it on Python 3 and I got an error. Anyone could explain why?
Code:
import logging
import logging.handlers
LOG_FILENAME = 'poller.log'
# Set up a specific logger with our desired output level
poll_logger = logging.getLogger('pollerLog')
# Add the log message handler to the logger
log_rotator = logging.handlers.TimedRotatingFileHandler(LOG_FILENAME, when='d', interval=1, backupCount=5, encoding=None, delay=False, utc=False)
poll_logger.addHandler(log_rotator)
# Roll over on application start
poll_logger.handlers[0].doRollover()
Error:
Traceback (most recent call last):
File "logR.py", line 10, in <module>
log_rotator = logging.handlers.TimedRotatingFileHandler(LOG_FILENAME, when='d', interval=1, back
upCount=5, encoding=None, delay=False, utc=False)
File "C:\LynxApps\Python31\lib\logging\handlers.py", line 206, in __init__
t = os.stat(filename)[ST_MTIME]
NameError: global name 'ST_MTIME' is not defined
I checked out the documents below and I don't see any difference:
Python v2 --> http://docs.python.org/library/logging.html#timedrotatingfilehandler
Python v3 --> http://docs.python.org/py3k/library/logging.handlers.html?highlight=logging#timedrotatingfilehandler
Upvotes: 2
Views: 807
Reputation: 33749
It's a bug in Python 3.1.3 (see the issue on bugs.python.org).
Supposedly it's fixed in Python 3.2.
Upvotes: 5