문제 설명
logging.config.fileConfig를 호출하면 로깅 시스템이 여러 번 실패합니다. (Logging system fails multiple times when I call logging.config.fileConfig)
Python 3.7.3에서 logging.config.fileConfig를 여러 번 호출하면 로깅 시스템이 자동으로 실패합니다. 이런 일이 발생하는 원인은 무엇입니까?
import logging.config
logging.config.fileConfig('logging.conf')
logger = logging.getLogger(__name__)
logger.error("I print")
logging.config.fileConfig('logging.conf')
logger.error("I do not")
해결 방법은 logging.config.fileConfig
호출에 대한 각 호출을 if __name__ == '__main__':
에서 래핑하는 것입니다. 더 나은 접근 방법
참조 솔루션
방법 1:
You need to ensure any existing loggers aren't disabled by calling like this:
logging.config.fileConfig('logging.conf', disable_existing_loggers=False)
This is documented here.
(by Jethro、Vinay Sajip)