Python logging.handlers: send log records to streams and files
Answer: The following useful handlers are provided in this package.
What is included
StreamHandler, FileHandler, and NullHandler are defined in the logging module itself, but documented here along with the other handlers.
StreamHandler sends logging output to streams such as sys.stdout, sys.stderr, or any object that supports write() and flush().
If stream is specified, the instance will use it for logging output.
Any file-like object that supports write() and flush() can be the stream.
How a file handler writes
FileHandler inherits the output functionality from StreamHandler.
If mode is not specified, 'a' is used.
The specified file is opened and used as the stream for logging.
The record is then written to the stream followed by terminator.
If you do not specify a stream, sys.stderr will be used.
See also
Claims
- id: C1 claim: The following useful handlers are provided in this package. source: S1 evidence: "The following useful handlers are provided in the package."
- id: C2 claim: If you omit the stream, sys.stderr will be used. source: S1 evidence: "otherwise, sys.stderr will be used"
- id: C3 claim: If mode is not specified, 'a' is used. source: S1 evidence: "If mode is not specified, 'a' is used"
- id: C4 claim: If a stream is given, StreamHandler uses it for output. source: S2 evidence: "If stream is specified, the instance will use it for logging output"
Sources
- [S1] logging.handlers — Logging handlers. Python Software Foundation. https://docs.python.org/3/library/logging.handlers.html . License: PSF License Version 2. Accessed 2026-11-24.
- [S2] logging.handlers documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/logging.handlers.rst . License: PSF License Version 2. Accessed 2026-11-24.
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.handlers — Logging handlers; CPython, logging.handlers documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, logging.handlers — Logging handlers; CPython, logging.handlers documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python logging.handlers: send log records to streams and files." iinventedlight Library, iil:note:591a29hg, version of 2026-11-24. https://iinventedlight.com/library/notes/python-logging-handlers/. License: CC-BY-4.0.
@misc{iil_note_591a29hg,
author = {{iinventedlight}},
title = {{Python logging.handlers: send log records to streams and files}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-24},
url = {https://iinventedlight.com/library/notes/python-logging-handlers/},
note = {Permanent ID iil:note:591a29hg. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- python-logging-handlers.schema.json (schema; CC-BY-4.0)
- python-logging-handlers.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-logging-handlers.md.