Python for Software Engineers
Back to Production Python

Logging & Configuration

Structured logging, log levels, and the 12-factor config pattern. The foundation of observable Python apps. FIND_VIDEO: search 'python logging configuration 12 factor' — recommended channel: ArjanCodes / mCoding. Aim for 10 min or under.

14 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.
Loading progress...

Key moments

  1. Logging Rationale — Explains why structured logging is superior to print statements for production monitoring.
  2. Basic Implementation — Demonstrates importing the logging module and replacing existing print statements.
  3. Standard Logging Levels — Introduces the five standard log levels and the default WARNING threshold.
  4. Default Threshold Behavior — Shows debug messages being suppressed until warning level calls are tested.
  5. Global Level Configuration — Uses basicConfig to set the minimum severity threshold to DEBUG.
  6. Persistent File Output — Configures basicConfig with a filename to redirect output from console to disk.
  7. Custom Output Formatting — Applies format string interpolation to customize log line structure and timestamps.
PDF notes

Frequently asked questions

Why do my logging.debug() and logging.info() calls produce no output by default?

Python's logging module defaults to a WARNING threshold, silently ignoring any messages with lower severity until basicConfig(level=logging.DEBUG) is set.

Does logging to a file overwrite previous logs each time the script runs?

No, by default basicConfig with a filename parameter appends new log lines to the end of the file, preserving historical records across executions.

What is the 'root' identifier that appears in default log messages?

It indicates the message was handled by the default top-level root logger configured by basicConfig.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.