Logging and Configuration

advanced level · ~20 min · Module 22: Professional Python Development

Use standard logging module instead of raw prints for production applications.

Learning objectives

  • Configure logging levels (DEBUG, INFO, WARNING, ERROR, CRITICAL)
  • Format logs with timestamps and loggers

Lesson material

The Logging Module

Logging provides flexible output channels for production debugging.

Example code

import logging

logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
logging.info("Application starting...")
logging.warning("Low disk space warning")

Practice exercise: Logging Configuration

Import logging. Log an error message `"Database Connection Failed"` using `logging.error()`.

Test yourself with the Module 22: Professional Python Development quiz →

View the full Python curriculum →