반응형
Python에서 루트 로거가 DEBUG 수준으로 설정되어 있는지 확인합니까?
다음과 같은 명령 줄 매개 변수를 사용하여 로깅 모듈을 DEBUG로 설정하면 :
if (opt["log"] == "debug"):
logging.basicConfig(level=logging.DEBUG)
로거가 DEBUG로 설정되었는지 나중에 어떻게 알 수 있습니까? True 플래그가 전달되면 함수의 시간을 측정하는 데코레이터를 작성하고 있으며 플래그가 제공되지 않으면 루트 로거가 DEBUG로 설정 될 때 기본적으로 타이밍 정보를 인쇄합니다.
logging.getLogger().getEffectiveLevel()
logging.getLogger()
인수없이 루트 수준 로거를 가져옵니다.
http://docs.python.org/library/logging.html#logging.Logger.getEffectiveLevel
실제로 더 좋은 방법이 있습니다logging.getLogger().isEnabledFor(logging.DEBUG)
. 코드를 사용하세요 . 의 결과로 무엇을해야하는지 이해하려고 노력하면서 찾았습니다 getEffectiveLevel()
.
다음은 로깅 모듈 자체가 사용하는 코드입니다.
def getEffectiveLevel(self):
"""
Get the effective level for this logger.
Loop through this logger and its parents in the blogger hierarchy,
looking for a non-zero logging level. Return the first one found.
"""
logger = self
while logger:
if logger.level:
return logger.level
logger = logger.parent
return NOTSET
def isEnabledFor(self, level):
"""
Is this logger enabled for level ‘level’?
"""
if self.manager.disable >= level:
return 0
return level >= self.getEffectiveLevel()
다만
logging.getLogger().level == logging.DEBUG
반응형
'code' 카테고리의 다른 글
명령 줄에서 Ansible 플레이 북의 호스트 변수 재정의 (0) | 2020.09.18 |
---|---|
왜“git push --set-upstream origin (0) | 2020.09.18 |
부울 필드를 인덱싱 할 때 성능이 향상됩니까? (0) | 2020.09.18 |
list.contains JSTL의 문자열 평가 (0) | 2020.09.18 |
iOS 장치 만 대상으로하는 CSS 미디어 쿼리 (0) | 2020.09.18 |