여러 모듈에서 사용할 수있는 로거를 작성하고 싶습니다. 한 곳에서 활성화 및 비활성화 할 수 있어야합니다. 그리고 재사용이 가능해야합니다.여러 모듈에 파이썬 로그인하기
다음은 시나리오입니다. switch_module.py
class Brocade(object):
def __init__(self, ip, username, password):
...
def connect(self):
...
def disconnect(self):
...
def switch_show(self):
...
switch_module_library.py
import switch_module
class Keyword_Mapper(object):
def __init__(self, keyword_to_execute):
self._brocade_object = switch_module.Brocade(ip, username, password)
...
def map_keyword_to_command(self)
...
application_gui.py
class GUI:
# I can open a file containing keyword for brocade switch
# in this GUI in a tab and tree widget(it uses PyQt which I don't know)
# Each tab is a QThread and there could be multiple tabs
# Each tab is accompanied by an execute button.
# On pressing exeute it will read the string/keywords from the file
# and create an object of keyword_Mapper class and call
# map_key_word_to_command method, execute the command on brocade
# switch and log the results. Current I am logging the result
# only from the Keyword_Mapper class.
내가 가진 문제는 의지 활성화 및 비활성화 할 수있는 로거를 작성하는 방법이며, 세 개의 모듈 모두에서 하나의 파일과 콘솔에 로깅해야합니다.
나는 세 가지 모듈 에서 가져 오기 다음 INT 평 글로벌 로거를 작성하고 시도가 동일한 파일에 로그인 할 수 있도록 공통의 이름을했지만, 다중 있기 때문에 다음 문제에 달렸다 -threading 그리고 나중에 에 logger를 생성하여 그 이름에 thread-id가있는 파일에 로그를 남기므로 각 로그마다 스레드 당 을 가질 수 있습니다.같은 파일이 아닌 다른 파일에 로그해야하는 경우 어떻게해야합니까?
필자는 파이썬 로그 기록 문서를 읽었지만 재사용 할 수있는 적절한 로깅 시스템을 작성하는 것에 대해 명확한 그림을 얻을 수 없습니다. .
I 인해 PyQt는 내가 여기에 로깅 주위에 내 머리를 얻을 수 없습니다입니다 멀티 스레딩을 사용하여 나 아닌 다른 사람에 의해 생성 된 GUI이 링크 Is it better to use root logger or named logger in Python
하지만 겪었습니다.