How to disable logging from imported modules in Python?

PythonServer Side ProgrammingProgramming

You can disable logging from imported modules using the logging module. You can configure it to not log messages unless they are at least warnings using the following code:

import logging

If you dont want to write the module name as a string, you can also use imported_module.__name__. If you want to go a level higher and only want to log messages when they are errors or critical, you can do replace logging.WARNING with logging.ERROR and logging.CRITICAL respectively.

Published on 20-Dec-2017 17:56:10