我正在使用Python日志记录模块,并希望禁用由我导入的第三方模块打印的日志消息。例如,我使用的内容如下所示:
logger = logging.getLogger()
logger.setLevel(level=logging.DEBUG)
fh = logging.StreamHandler()
fh_formatter = logging.Formatter('%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s')
fh.setFormatter(fh_formatter)
logger.addHandler(fh)
这会在我执行logger.debug(“我的消息!”)时打印出我的调试消息,但它也会打印出我导入的任何模块的调试消息(例如请求和许多其他内容)。
我只想看到来自我感兴趣的模块的日志消息。有没有可能让日志模块做到这一点?
理想情况下,我希望能够告诉记录器打印来自"ModuleX,ModuleY“的消息,并忽略所有其他消息。
我查看了以下内容,但我不希望在每次调用导入的函数之前禁用/启用日志记录:logging - how to ignore imported module logs?
https://stackoverflow.com/questions/35325042
复制相似问题