Python Logging - Disable logging from imported modules

前端 未结 10 835
清酒与你
清酒与你 2020-12-12 12:52

I\'m using the Python logging module, and would like to disable log messages printed by the third party modules that I import. For example, I\'m using something like the fo

10条回答
  •  渐次进展
    2020-12-12 13:24

    Another thing to consider is the propagate property of the Logger class.

    For example, py-suds library for handling soap calls, even put to ERROR

    logging.getLogger('suds.client').setLevel(logging.ERROR)
    logging.getLogger('suds.transport').setLevel(logging.ERROR)
    logging.getLogger('suds.xsdschema').setLevel(logging.ERROR)
    logging.getLogger('suds.wsdl').setLevel(logging.ERROR)
    

    logs logs about a module called sxbasics.py creationg a huge amount of logs

    that because the propagation of the logs is True by default, setting to False, instead, i recovered 514MB of logs.

    import logging
    logging.getLogger("suds").propagate = False
    logging.getLogger('suds.client').setLevel(logging.ERROR)
    logging.getLogger('suds.transport').setLevel(logging.ERROR)
    logging.getLogger('suds.xsdschema').setLevel(logging.ERROR)
    logging.getLogger('suds.wsdl').setLevel(logging.ERROR)
    

提交回复
热议问题