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 following:
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)
This prints out my debug messages when I do a logger.debug("my message!"), but it also prints out the debug messages from any module I import (such as requests, and a number of other things).
I'd like to see only the log messages from modules I'm interested in. Is it possible to make the logging module do this?
Ideally, I'd like to be able tell the logger to print messages from "ModuleX, ModuleY" and ignore all others.
I looked at the following, but I don't want to have to disable/enable logging before every call to an imported function: logging - how to ignore imported module logs?