Lesson 34 of 55
PythonLogging
20 minutes
Course progress62%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 34 of 55
Python20 minutes
Keep these ideas in mind as you work through the lesson.
Instead of scattering print() statements, use the logging module for flexible, configurable output.
import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logging.debug('Debug message') # Not shown at INFO level
logging.info('Info message')
logging.warning('Warning message')
You can direct logs to the console, files, rotate them, and adjust verbosity on the fly—essential for production‑grade applications.