Python Logging - Disable logging from imported modules
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
If imported modules are polluting your logs, the fix is usually to configure their loggers explicitly rather than disabling Python logging globally. The clean approach is to identify the noisy logger names, raise their level, stop their propagation, or attach a NullHandler depending on how much output you want to suppress.
Understand the Logger Hierarchy First
Python loggers are hierarchical. A library often logs under names such as urllib3, botocore, or matplotlib, and those log records propagate upward to the root logger unless configured otherwise.
That means you usually do not need to modify the library code. You only need to configure the right logger name in your application.
Suppress One Specific Imported Module
To silence a known noisy module, get its logger and disable it:
This is blunt but effective. A more flexible option is to keep only warnings or errors:
That suppresses low-value debug and info output while preserving higher-severity events.
Prevent Propagation to the Root Logger
Some libraries attach their own handlers or emit records that bubble up to your root logger. In that case, disable propagation:
This pattern is useful when a library insists on creating records but you do not want them reaching your application handlers.
Configure Logging Centrally
For larger projects, dictConfig is cleaner than scattered one-off logger tweaks.
This keeps your application logging policy in one place and makes it obvious which third-party modules are being quieted.
Avoid Global Shutdown Unless You Mean It
Python also has a global switch:
That disables all logging at CRITICAL and below for the entire process. It is almost never what you want in an application, because it silences your own logs too. Use it only for very controlled scripting or tests where total silence is intentional.
Order of Configuration Matters
Configure logging early in process startup. If imported modules emit logs during import time or initialize their handlers before your app config runs, you may still see unwanted output. In those cases, move your logging setup to the very beginning of program startup.
If a library writes directly with print instead of logging, none of these logger settings will help. That is a different problem and must be handled separately.
Common Pitfalls
- Muting the root logger when the real problem is only one noisy imported library.
- Guessing the library logger name instead of confirming it from actual log output.
- Disabling a dependency completely and then losing warnings that would have been operationally useful.
- Configuring suppression too late, after the imported module already emitted startup logs.
- Setting
disable_existing_loggerstoo aggressively indictConfigand silencing more than intended.
Summary
- Silence imported modules by configuring their specific logger names.
- Prefer
setLevel,propagate = False, orNullHandlerover disabling all logging globally. - Use
dictConfigfor centralized, repeatable logging policy. - Configure logging early so third-party modules do not emit before your setup runs.
- If output comes from
printrather thanlogging, logger settings will not affect it.
Related reading
- Python logging not outputting anything
- Python logging use milliseconds in time format
- Q How to rewrite single path among many with the ingress-nginx
- Query EC2 tags from within instance
- python max function using 'key' and lambda expression
- Python maximum recursion depth exceeded while calling a Python object
- RabbitMQ ** WARNING ** Mnesia is overloaded
- RabbitMQ connection through Nginx

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.