2
我可以在Python 2中使用下面的代碼。我在Python 3上嘗試了它,並且出現錯誤。任何人都能解釋爲什麼Python v3日誌記錄
代碼:
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()
錯誤:
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
我檢查了下面的文件,我看不出有任何區別:
Python的V2 - >http://docs.python.org/library/logging.html#timedrotatingfilehandler
Python v3 - >http://docs.python.org/py3k/library/logging.handlers.html?highlight=logging#timedrotatingfilehandler
啊..這是有道理的。非常感謝。 – LynxLee 2011-03-04 06:56:31
是的,我測試了這個3.1.2,它在那裏工作。 – 2011-03-04 06:56:43
是的,3.2作品。 – LynxLee 2011-03-04 07:33:27