如何禁用特定导入的日志记录



我正在尝试使用pyttsx3对于一个简单的语音消息,但是如果我把它放在一个try except块中,虽然语音消息生成了,但是生成了许多不需要的调试日志打印,有没有办法禁用这个特定模块的日志记录pyttsx3我尝试了logging.getLogger("pyttsx3").setLevel(logging.INFO),但它没有帮助

import logging
import pyttsx3
logging.basicConfig(
level=logging.DEBUG,
format="[%(lineno)d] [%(asctime)s] -- %(name)s  %(levelname)s: %(message)s",
)
logging.getLogger("pyttsx3").setLevel(logging.INFO)
engine = pyttsx3.init()
try:
logging.info("Normal Logging msg")
engine.say("hello")
engine.runAndWait()
except Exception as e:
logging.debug(e)

下面是不需要的调试打印

[150] [2021-10-21 13:51:39,161] -- comtypes  DEBUG: CoInitializeEx(None, 2)
[92] [2021-10-21 13:51:39,345] -- comtypes.client._code_cache  INFO: Imported existing <module 'comtypes.gen' from 'C:\Python38\lib\site-packages\comtypes\gen\__init__.py'>
[73] [2021-10-21 13:51:39,346] -- comtypes.client._code_cache  INFO: Using writeable comtypes cache directory: 'C:Python38libsite-packagescomtypesgen'
[228] [2021-10-21 13:51:39,391] -- comtypes.client  DEBUG: SAPI.SPVoice -> {96749377-3391-11D2-9EE3-00C04F797396}
[236] [2021-10-21 13:51:39,391] -- comtypes.client  DEBUG: CoCreateInstance({96749377-3391-11D2-9EE3-00C04F797396}, clsctx=None, interface=None)
[59] [2021-10-21 13:51:39,410] -- comtypes.client  DEBUG: GetBestInterface(<POINTER(IUnknown) ptr=0x1a5a04d0b90 at 1a5a02050c0>)
[63] [2021-10-21 13:51:39,411] -- comtypes.client  DEBUG: Does implement IProvideClassInfo
[99] [2021-10-21 13:51:39,412] -- comtypes.client  DEBUG: Default interface is {269316D8-57BD-11D2-9EEE-00C04F797396}
[911] [2021-10-21 13:51:39,413] -- comtypes  DEBUG: Release <POINTER(IUnknown) ptr=0x1a5a04d0bd0 at 1a5a0205540>
[115] [2021-10-21 13:51:39,413] -- comtypes.client._generate  DEBUG: GetModule(TLIBATTR(GUID={C866CA3A-32F7-11D2-9602-00C04F8EE628}, Version=5.4, LCID=0, FLags=0x8))
[113] [2021-10-21 13:51:39,413] -- comtypes.client  DEBUG: Implements default interface from typeinfo <class 'comtypes.gen._C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.ISpeechVoice'>
[127] [2021-10-21 13:51:39,413] -- comtypes.client  DEBUG: Final result is <POINTER(ISpeechVoice) ptr=0x1a5a04d0bd0 at 1a5a02054c0>
[911] [2021-10-21 13:51:39,413] -- comtypes  DEBUG: Release <POINTER(IProvideClassInfo) ptr=0x1a5a04d0bf0 at 1a5a0205140>
[911] [2021-10-21 13:51:39,413] -- comtypes  DEBUG: Release <POINTER(ITypeInfo) ptr=0x1a59fbed7d8 at 1a5a02051c0>
[911] [2021-10-21 13:51:39,413] -- comtypes  DEBUG: Release <POINTER(ITypeInfo) ptr=0x1a59fbed830 at 1a5a0205340>
[911] [2021-10-21 13:51:39,413] -- comtypes  DEBUG: Release <POINTER(ITypeLib) ptr=0x1a59f51e000 at 1a5a0205540>
[911] [2021-10-21 13:51:39,413] -- comtypes  DEBUG: Release <POINTER(IUnknown) ptr=0x1a5a04d0b90 at 1a5a02050c0>
[72] [2021-10-21 13:51:39,414] -- comtypes.client._events  DEBUG: <POINTER(ISpeechVoice) ptr=0x1a5a04d0bd0 at 1a5a02054c0> using sinkinterface from clsid <class 'comtypes.gen._C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4._ISpeechVoiceEvents'>
[911] [2021-10-21 13:51:39,414] -- comtypes  DEBUG: Release <POINTER(IProvideClassInfo2) ptr=0x1a5a04d0bf0 at 1a5a01b5440>
[238] [2021-10-21 13:51:39,414] -- comtypes._comobject  DEBUG: <comtypes.client._events.CreateEventReceiver.<locals>.Sink object at 0x000001A59117DFA0>: _ISpeechVoiceEvents.VoiceChange not implemented
[238] [2021-10-21 13:51:39,414] -- comtypes._comobject  DEBUG: <comtypes.client._events.CreateEventReceiver.<locals>.Sink object at 0x000001A59117DFA0>: _ISpeechVoiceEvents.Bookmark not implemented
[238] [2021-10-21 13:51:39,414] -- comtypes._comobject  DEBUG: <comtypes.client._events.CreateEventReceiver.<locals>.Sink object at 0x000001A59117DFA0>: _ISpeechVoiceEvents.Word not implemented
[238] [2021-10-21 13:51:39,414] -- comtypes._comobject  DEBUG: <comtypes.client._events.CreateEventReceiver.<locals>.Sink object at 0x000001A59117DFA0>: _ISpeechVoiceEvents.Sentence not implemented
[238] [2021-10-21 13:51:39,414] -- comtypes._comobject  DEBUG: <comtypes.client._events.CreateEventReceiver.<locals>.Sink object at 0x000001A59117DFA0>: _ISpeechVoiceEvents.Phoneme not implemented
[238] [2021-10-21 13:51:39,415] -- comtypes._comobject  DEBUG: <comtypes.client._events.CreateEventReceiver.<locals>.Sink object at 0x000001A59117DFA0>: _ISpeechVoiceEvents.Viseme not implemented
[238] [2021-10-21 13:51:39,415] -- comtypes._comobject  DEBUG: <comtypes.client._events.CreateEventReceiver.<locals>.Sink object at 0x000001A59117DFA0>: _ISpeechVoiceEvents.AudioLevel not implemented
[238] [2021-10-21 13:51:39,415] -- comtypes._comobject  DEBUG: <comtypes.client._events.CreateEventReceiver.<locals>.Sink object at 0x000001A59117DFA0>: _ISpeechVoiceEvents.EnginePrivate not implemented
[22] [2021-10-21 13:51:39,415] -- comtypes.client._events  DEBUG: Start advise <class 'comtypes.gen._C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4._ISpeechVoiceEvents'>
[606] [2021-10-21 13:51:39,415] -- comtypes._comobject  DEBUG: <comtypes.client._events.CreateEventReceiver.<locals>.Sink object at 0x000001A59117DFA0>.QueryInterface({A372ACD1-3BEF-4BBD-8FFB-CB3E2B416AF8}) -> S_OK
[547] [2021-10-21 13:51:39,415] -- comtypes._comobject  DEBUG: 1 active COM objects: Added   <comtypes.client._events.CreateEventReceiver.<locals>.Sink object at 0x000001A59117DFA0>
[575] [2021-10-21 13:51:39,415] -- comtypes._comobject  DEBUG: <comtypes.client._events.CreateEventReceiver.<locals>.Sink object at 0x000001A59117DFA0>.AddRef() -> 1
[911] [2021-10-21 13:51:39,425] -- comtypes  DEBUG: Release <POINTER(IConnectionPointContainer) ptr=0x1a5a04d0bf8 at 1a5a0205740>
[40] [2021-10-21 13:51:39,488] -- comtypes.client  DEBUG: wrap_outparam(<POINTER(ISpeechObjectToken) ptr=0x1a5a04d6300 at 1a5a0205740>)
[911] [2021-10-21 13:51:39,488] -- comtypes  DEBUG: Release <POINTER(ISpeechObjectToken) ptr=0x1a5a04d6300 at 1a5a0205740>
[40] [2021-10-21 13:51:39,488] -- comtypes.client  DEBUG: wrap_outparam(<POINTER(ISpeechObjectTokens) ptr=0x1a5a04d7760 at 1a5a0205740>)
[911] [2021-10-21 13:51:39,488] -- comtypes  DEBUG: Release <POINTER(IUnknown) ptr=0x1a5a04d70d0 at 1a5a02058c0>
[40] [2021-10-21 13:51:39,489] -- comtypes.client  DEBUG: wrap_outparam(<POINTER(IDispatch) ptr=0x1a5a04d7940 at 1a5a02059c0>)
[59] [2021-10-21 13:51:39,489] -- comtypes.client  DEBUG: GetBestInterface(<POINTER(IDispatch) ptr=0x1a5a04d7940 at 1a5a02059c0>)
[67] [2021-10-21 13:51:39,489] -- comtypes.client  DEBUG: Does NOT implement IProvideClassInfo, trying IProvideClassInfo2
[86] [2021-10-21 13:51:39,489] -- comtypes.client  DEBUG: Does NOT implement IProvideClassInfo/IProvideClassInfo2
[911] [2021-10-21 13:51:39,490] -- comtypes  DEBUG: Release <POINTER(IUnknown) ptr=0x1a59fbed8e0 at 1a5a0205bc0>
[99] [2021-10-21 13:51:39,490] -- comtypes.client  DEBUG: Default interface is {C74A3ADC-B727-4500-A84A-B526721C8B8C}
[911] [2021-10-21 13:51:39,490] -- comtypes  DEBUG: Release <POINTER(IUnknown) ptr=0x1a5a04d7940 at 1a5a0205cc0>
[115] [2021-10-21 13:51:39,490] -- comtypes.client._generate  DEBUG: GetModule(TLIBATTR(GUID={C866CA3A-32F7-11D2-9602-00C04F8EE628}, Version=5.4, LCID=0, FLags=0x8))
[113] [2021-10-21 13:51:39,490] -- comtypes.client  DEBUG: Implements default interface from typeinfo <class 'comtypes.gen._C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.ISpeechObjectToken'>
[127] [2021-10-21 13:51:39,490] -- comtypes.client  DEBUG: Final result is <POINTER(ISpeechObjectToken) ptr=0x1a5a04d7940 at 1a5a0205bc0>
[911] [2021-10-21 13:51:39,490] -- comtypes  DEBUG: Release <POINTER(IDispatch) ptr=0x1a5a04d7940 at 1a5a0205b40>
[911] [2021-10-21 13:51:39,490] -- comtypes  DEBUG: Release <POINTER(ITypeInfo) ptr=0x1a59fbed8e0 at 1a5a0205c40>
[911] [2021-10-21 13:51:39,490] -- comtypes  DEBUG: Release <POINTER(ITypeLib) ptr=0x1a59f51e000 at 1a5a0205cc0>
[911] [2021-10-21 13:51:39,490] -- comtypes  DEBUG: Release <POINTER(IDispatch) ptr=0x1a5a04d7940 at 1a5a02059c0>
[911] [2021-10-21 13:51:39,490] -- comtypes  DEBUG: Release <POINTER(IEnumVARIANT) ptr=0x1a5a04d70d0 at 1a5a0205840>
[911] [2021-10-21 13:51:39,490] -- comtypes  DEBUG: Release <POINTER(ISpeechObjectTokens) ptr=0x1a5a04d7760 at 1a5a0205740>
[911] [2021-10-21 13:51:39,490] -- comtypes  DEBUG: Release <POINTER(ISpeechObjectToken) ptr=0x1a5a04d7940 at 1a5a0205bc0>
[11] [2021-10-21 13:51:39,490] -- root  INFO: Normal Logging msg

由于日志记录来自comtypes,而不是pyttsx3,也许可以试试这个:logging.getLogger("comtypes").setLevel(logging.INFO)

相关内容

  • 没有找到相关文章

最新更新