Logging in Python
The logging module is Python's built-in, standard way to record what a program is doing while it runs — far more capable than scattering print() statements throughout code, since logging supports severity levels, timestamps, and configurable destinations like a file, without needing to touch the code that generates each message.
import logging
Brings in the module, ready to use with sensible defaults.
Each call has a severity level
debug(), info(), warning(), error(), and critical(), from least to most severe.
Only warning() and above show by default
debug() and info() stay suppressed unless the level is configured lower.
basicConfig() controls what’s shown
Sets the minimum level, and can redirect output to a file instead of the console.
Logging can be toggled without touching the code
Unlike print(), messages can be turned on, off, or redirected purely through configuration.
import logging logging.basicConfig(level=logging.INFO) logging.debug("This won't show by default")logging.info("Starting process")logging.warning("Disk space is low")logging.error("Failed to save file")Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Python yourself — building beats watching.