Python for Data 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. Motivation for Logging — Explains why structured logging replaces ad-hoc print statements to observe application trends and errors over time.
  2. Standard Log Levels — Introduces the five standard log levels and demonstrates default suppression of DEBUG and INFO messages.
  3. Configuring Threshold Levels — Demonstrates setting the root logger threshold to DEBUG using logging.basicConfig and numeric level constants.
  4. Logging to Files — Configures the filename parameter in basicConfig to append execution records persistently to disk.
  5. Customizing Log Format — Applies format string codes like asctime, levelname, and message to generate structured log outputs.
  6. Applying Logging to Classes — Implements file-based INFO logging inside an Employee class to record instance creation events over time.
PDF notes

Frequently asked questions

Why does logging.basicConfig not display DEBUG logs in the console by default?

Python's default logging threshold is set to WARNING, which automatically suppresses all DEBUG and INFO messages unless explicitly configured otherwise.

What is the difference between logging.DEBUG and logging.debug()?

logging.DEBUG is an uppercase integer constant (value 10) used for configuration, whereas logging.debug() is the callable method that emits a log record.

Does writing to a log file overwrite existing logs upon re-running the script?

No, logging.basicConfig appends new log records to the end of the specified file, preserving history across runs.

What are the common format codes for standardizing log message outputs?

Common LogRecord attributes include %(asctime)s for timestamps, %(levelname)s for severity names, and %(message)s for the log text.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.