2016-06-24 1 views
0

커스텀 로거를 만드는 법을 배우려하고 있습니다. 나는 아래 정확히 오류가 확실하지 않으므로 누구나 나를 올바른 방향으로 인도 할 수 있다면 좋을 것입니다. 사용자 정의 로거 오류입니까?

내가 가져오고 내 launcher.py 파일에서 로거를 실행

...

import custom_logging as logging 
logging.getLogger(__name__) 

는이 오류 얻을 : 내가 아는

No handlers could be found for logger "mb.custom-logger" 

을 그 로거의 custom-logger 부분 이름이 custom_logger/__init__.py 파일 내에 있음 ...

... a bunch of code 

log = getLogger('mb-logger') 
log.warning('Creating log : {0}'.format(log_file)) 

그러나 mb 부분이 오류 메시지 또는 그와 관련된 부분에서 비롯된 것인지 확실하지 않습니다. 이견있는 사람? 또한

일부 컨텍스트를 제공하기 위해, 내 프로젝트는 다음과 같이 설정 :

Project_Root/ 
    bin/ 
     launcher.py (this is where the error is occurring) 
    modules/ 
     custom-logger/ 
      source/ 
       custom_logger/ 
        __init__.py (this is where the custom logger is created) 
+1

아마도'__init __. py' 스크립트에서 커스텀 로거가 생성되는 방법을 보여 주어야 할 것입니다. – martineau

+0

[프로젝트의 디렉토리 구조] (http://docs.python-guide.org/en/latest/writing/structure/#structure-of-the-repository) – miraculixx

답변

1

마지막으로 문제가 발견되었습니다. @martineau는 코드를 보여줄 것을 제안 했으므로 편집하기 시작했습니다. 그 과정에서 나는 오류를 발견했다!

내 초기 질문에 대답하기 위해 오류 메시지의 mb은 root_logger를 참조합니다.

내 custom_logger/ .py 내에서 getLogger 메소드를 재정의 할 때, 리턴하는 로거가 루트 로거와 일치하지 않습니다. 그래서 같이 :

오류 코드 : 고정

root_logger = getLogger(mb_tool)     # Name that needs to match = 'mb_tool' 

def getLogger(name='default'): 
    for handler in root_logger.handlers: 
     handler.setLevel(DEBUG) 
    return logging.getLogger(mb.{0}'.format(name)) # Name that doesn't match = 'mb' 

:

root_logger = getLogger(mb_tool) 

def getLogger(name='default'): 
    for handler in root_logger.handlers: 
     handler.setLevel(DEBUG) 
    return logging.getLogger(mb_tool.{0}'.format(name)) 

mbmb_tool에 고정 된 모든 변경. 도움을 청할 시간을내어 주셔서 감사합니다.

+0

Stackoverflow는 자신의 대답을 받아 들일 수 있습니다. –

1

Python - No handlers could be found for logger "OpenGL.error"에 따르면, 코드를 디버깅하는 당신이 필요합니다 :

import custom_logging as logging 
logging.basicConfig() 

을 그리고 당신이 볼 수 명령 행 출력의 오류 세부 사항.

로깅 모듈을 수정했다고 가정합니다.

+0

내 custom_logger/__ init__.py에 단순화 할 수 있습니다. 이 예제에서와 같이 사전을 사용하여 로거 설정을 편집합니다. http://docs.python-guide.org/en/latest/writing/logging/ logging.config.dictConfig (log_settings); logging.captureWarnings (True); basicConfig()를 호출하면 내 맞춤 설정이 무시됩니까? –

+0

또한 'mb'는'mb.custom_logger'에서 무엇을 말합니까? –

관련 문제