user17096496
user17096496

Reputation:

How to disable logging for a particular import

I am trying to use pyttsx3 for a simple voice message but if i put this in a try except block though the voice message is generated there are many unwanted debug logging prints generated ,Is there any way to disable logging for this particular module pyttsx3 I tried the logging.getLogger("pyttsx3").setLevel(logging.INFO) but it didn't help

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)

Below are the unwanted debug prints

[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:\Python38\lib\site-packages\comtypes\gen'
[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

Upvotes: 1

Views: 362

Answers (1)

T&#245;nis Piip
T&#245;nis Piip

Reputation: 492

Since the logging comes from comtypes, not pyttsx3, maybe try this: logging.getLogger("comtypes").setLevel(logging.INFO)

Upvotes: 2

Related Questions