Overview
I want to use httpimport as a logging library common to several scripts. This module generates logs of its own which I do not know how to silence.
In other cases such as this one, I would have used
logging.getLogger('httpimport').setLevel(logging.ERROR) but it did not work.
Details
The following code is a stub of the "common logging code" mentioned above:
# toconsole.py import logging import os log = logging.getLogger(__name__) log.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s %(message)s') handler_console = logging.StreamHandler() level = logging.DEBUG if 'DEV' in os.environ else logging.INFO handler_console.setLevel(level) handler_console.setFormatter(formatter) log.addHandler(handler_console) # disable httpimport logging except for errors+ logging.getLogger('httpimport').setLevel(logging.ERROR) A simple usage such as
import httpimport httpimport.INSECURE = True with httpimport.remote_repo(['githublogging'], 'http://localhost:8000/') : from toconsole import log log.info('yay!') gives the following output
[!] Using non HTTPS URLs ('http://localhost:8000//') can be a security hazard! 2019-08-25 13:56:48,671 yay! yay! The second (bare) yay! must be coming from httpimport, namely from its logging setup.
How can I disable the logging for such a module, or better - raise its level so that only errors+ are logged?
Note: this question was initially asked at the Issues section of the GitHub repository for httpimport but the author did not know either how to fix that.