Interview Prep/Python for DevOps/Exceptions, context managers, files & logging

What is the logger hierarchy and propagation?

AdvancedConceptExceptions, context managers, files & logging
Answer

Loggers are named with dots, forming a tree: cloudaudit.checks is a child of cloudaudit, which is a child of the root logger. A record is handled by the logger's own handlers and then propagates to ancestors' handlers (unless propagate = False). The effective level is the first level set walking up the tree.

Two classic bugs: duplicate log lines (a handler was added both to a child and to root), and silence (a library logger set to WARNING while you expected DEBUG). logging.getLogger("urllib3").setLevel(logging.WARNING) quiets noisy dependencies.

All Python for DevOps questions Roadmap: Python for automation

More on Exceptions, context managers, files & logging