내 파이썬 프로젝트에 로깅을 구현하는 동안 몇 가지 문제가있는 것 같습니다.파이썬 로깅 설정 파일
단순히 다음과 같은 구성을 모방하려고 해요 :
Python Logging to Multiple Destinations
을하지만 대신에이 코드 내부를하고, 나는 구성 파일에 그것을 가지고 싶습니다. 다음은
내 설정 파일입니다[loggers]
keys=root
[logger_root]
handlers=screen,file
[formatters]
keys=simple,complex
[formatter_simple]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
[formatter_complex]
format=%(asctime)s - %(name)s - %(levelname)s - %(module)s : %(lineno)d - %(message)s
[handlers]
keys=file,screen
[handler_file]
class=handlers.TimedRotatingFileHandler
interval=midnight
backupCount=5
formatter=complex
level=DEBUG
args=('logs/testSuite.log',)
[handler_screen]
class=StreamHandler
formatter=simple
level=INFO
args=(sys.stdout,)
문제는 내 화면 출력의 모습이다 :
2010-12-14 11 : 39 : 04,066 - 루트 - 경고 - 3
2010-12 -14 11 : 39 : 04,066 - 루트 - ERROR - 4
2010-12-14 11 : 39 : 04,066 - 루트 - CRITICAL - 5
내 파일이 출력이지만, 함께 있지만 (위와 동일한 보이는 추가 정보 포함). 그러나 디버그 및 정보 수준은 출력되지 않습니다.
내가 여기
파이썬 2.7에 나는 내 간단한 예를 실패 보여주고있다 : 루트 로거에 다음 줄을 추가
import os
import sys
import logging
import logging.config
sys.path.append(os.path.realpath("shared/"))
sys.path.append(os.path.realpath("tests/"))
class Main(object):
@staticmethod
def main():
logging.config.fileConfig("logging.conf")
logging.debug("1")
logging.info("2")
logging.warn("3")
logging.error("4")
logging.critical("5")
if __name__ == "__main__":
Main.main()