---
source: https://iinventedlight.com/library/notes/python-logging.md
title: "Python logging: loggers, handlers, and the root logger"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, logging — Logging facility for Python; CPython, logging documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-26
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-26
as_of: 2026-11-26
confidence: medium
untested: "Not reproduced (2026-11-26). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-logging"
tags: [python, logging, logger, handler, root-logger]
client: Librarian
sources:
  - id: S1
    title: "logging — Logging facility for Python"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/logging.html
    accessed: 2026-11-26
    license: "PSF License Version 2"
  - id: S2
    title: "logging documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/logging.rst
    accessed: 2026-11-26
    license: "PSF License Version 2"
---
# Python logging: loggers, handlers, and the root logger
**Answer:** Python's logging package implements a flexible event logging system that applications and libraries can share.

## Loggers, handlers, filters, and formatters

The module defines functions and classes that implement event logging for applications and libraries.

Idiomatic usage creates a module level logger and uses that logger for logging.

Those messages travel to handlers on higher loggers, and finally to the root logger, which is hierarchical logging.

Logging is useful only after you configure it, including the levels and destinations for each logger.

In most cases only the root logger needs to be so configured, since lower level loggers forward their messages to it.

basicConfig() provides a quick way to configure the root logger for many use cases.

Loggers are the interface application code calls.

Handlers send the records that loggers create to the right destination.

Filters provide a finer grained facility for determining which log records to include.

Formatters specify the layout of log records in the final output.

## How to obtain a logger

Do not construct Logger objects yourself; call the module-level logging.getLogger(name) function instead.

Repeated getLogger() calls with the same name return the same Logger object.

A logger name is often a period-separated hierarchy, similar to a Python package path, and it can also be a plain name.

Loggers further down in the hierarchical list are children of loggers higher up, and all loggers are descendants of the root logger.

If you name loggers with __name__ on a per-module basis, the logger tree matches the package tree.

## See also

- [python-logging-basics](https://iinventedlight.com/library/notes/python-logging-basics/)
- [python-logging-config](https://iinventedlight.com/library/notes/python-logging-config/)
- [python-logging-handlers](https://iinventedlight.com/library/notes/python-logging-handlers/)

## Claims

- id: C1
  claim: Application code should call getLogger rather than construct Logger objects.
  source: S1
  evidence: "Loggers should NEVER be instantiated directly"

- id: C2
  claim: getLogger returns the same object when called again with the same name.
  source: S1
  evidence: "Multiple calls to getLogger() with the same name will always return a reference"

- id: C3
  claim: Loggers should never be constructed directly; call getLogger instead.
  source: S2
  evidence: "Loggers should *never* be instantiated directly"

## Sources

- [S1] logging — Logging facility for Python. Python Software Foundation. https://docs.python.org/3/library/logging.html . License: PSF License Version 2. Accessed 2026-11-26.

- [S2] logging documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/logging.rst . License: PSF License Version 2. Accessed 2026-11-26.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, logging — Logging facility for Python; CPython, logging documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
