Python › Logging

What's the difference between propagate=True and propagate=False on a logger?

Intermediate

Answer

By default (propagate=True), a log record handled by a child logger also passes up to its parent loggers' handlers, all the way to the root logger, potentially causing duplicate output if both the child and an ancestor have handlers. Setting propagate=False stops a logger from passing records upward, confining output to just its own handlers.
logger = logging.getLogger('myapp.module')
logger.propagate = False  # won't also trigger root logger's handlers
logger.addHandler(logging.StreamHandler())
Real-world example A module that logs very frequently sets propagate=False and attaches its own dedicated handler to avoid flooding the application's shared root-level log file.

Common follow-ups: How do you detect duplicate log lines caused by propagation?;When is propagation actually desirable?