2

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

1 Answer 1

5

It's a bug in Python 3.1.3 (see the issue on bugs.python.org).

Supposedly it's fixed in Python 3.2.

Sign up to request clarification or add additional context in comments.

2 Comments

Ahh.. that made sense. Thanks a lot.
The bugfix will also be included in 3.1.4, which should be released some time in the next few months.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.