2011-03-04 5 views
2

아래의 코드를 Python 2에서 사용할 수 있습니다. Python 3에서이 코드를 사용했지만 오류가 발생했습니다. 누구든지 이유를 설명 할 수 있습니까?Python v3 Logging

코드 :

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 

:

파이썬 V2 ->http://docs.python.org/library/logging.html#timedrotatingfilehandler

Python v3 ->http://docs.python.org/py3k/library/logging.handlers.html?highlight=logging#timedrotatingfilehandler

답변

5

이것은 Python 3.1.3의 버그입니다 (issue on bugs.python.org 참조).

아마도 파이썬 3.2에서 수정되었습니다.

+0

아 ... 말이 맞았습니다. 고마워. – LynxLee

+0

예, 3.1.2로 테스트했는데 작동합니다. –

+0

그래, 3.2 작품. – LynxLee