logfmter
A Python package which supports global logfmt formatted logging.
What it is and what it does
Logfmter is a Python logging formatter that converts stdlib logging output into logfmt structured format—a key-value log format designed for both human readability and machine parsing. It integrates as a standard logging.Formatter, so you pass it to a handler and all logs automatically emit as logfmt without touching any existing log statements. The formatter accepts configuration for which fields to include (like log level, timestamp, process name), custom key-to-LogRecord-attribute mappings, default values, and fields to exclude.
The package handles both simple log messages and extra dictionaries passed to logging calls, formatting them as space-separated key=value pairs. It supports subclassing for custom value formatting and can template default values using format strings. With no external dependencies and active maintenance, it's designed as a drop-in way to adopt structured logging in existing applications.
Use it for:
- Adopt structured logging in an existing application without rewriting log statements.
- Ensure all third-party library logs conform to a single logfmt format for centralized log aggregation.
- Add trace IDs, request IDs, or other context fields to all logs via defaults without modifying each call.
- Parse logs programmatically or feed them to log aggregation tools that expect key-value structure.
- Customize log field names and values by subclassing to match your organization's logging schema.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Formats Python stdlib logging output as logfmt structured logs without modifying existing log calls, enabling both human and machine-readable output.
Yes. Logfmter is a lightweight, dependency-free formatter that solves a real problem—adopting structured logging without refactoring existing code. Active maintenance, permissive license, no known vulnerabilities, and low install friction make it a safe choice. Install if you need logfmt output from stdlib logging.
Install
logfmter on PyPI
pip
pip install logfmteruv
uv add logfmterpoetry
poetry add logfmterInstalling logfmter
Before you install
Low friction: pure Python wheel with no runtime dependencies. Actively maintained with recent releases; last commit 2026-06-05.
License in practice
MIT license permits free use, modification, and distribution with minimal restrictions.
Quickstart
import logging
from logfmter import Logfmter
handler = logging.StreamHandler()
handler.setFormatter(Logfmter())
logging.basicConfig(handlers=[handler])
logging.error("hello", extra={"alpha": 1})
Requires Python 3.10 or later.
Verify before relying
- Performance characteristics when formatting high-volume logs or large extra dictionaries.
- Compatibility with async logging frameworks or concurrent logging scenarios.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 156 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 210,617/month — #9,490 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: logfmter-0.0.12-py3-none-any.whl
Tags
More Monitoring packages
Wraps any iterable to display a real-time…
copyleft · top 100 on PyPI
opentelemetry-semantic-conventionsProvides generated Python code for…
permissive · top 100 on PyPI
opentelemetry-sdkProvides the reference implementation of the…
permissive · top 100 on PyPI
opentelemetry-apiProvides the abstract API and interfaces for…
permissive · top 100 on PyPI
opentelemetry-exporter-otlp-proto-httpExports OpenTelemetry observability data to an…
permissive · top 1,000 on PyPI
opentelemetry-instrumentationProvides automatic instrumentation commands and…
permissive · top 1,000 on PyPI
daiquiriDaiquiri simplifies Python logging…
permissive · top 15,000 on PyPI
jsonformatterFormats Python logging output as JSON, enabling…
permissive · top 15,000 on PyPI
logging-formatter-anticrlfA drop-in replacement for Python's standard…
permissive · top 15,000 on PyPI
logging-jsonFormats Python logging records as JSON output,…
permissive · top 15,000 on PyPI
structlogstructlog is a structured logging library that…
permissive · top 1,000 on PyPI
python-json-loggerFormats Python logging output as JSON, making…
permissive · top 1,000 on PyPI
fluent-loggerSends structured event logs from Python…
unclear · top 5,000 on PyPI
mdcAdds Mapped Diagnostic Context (MDC) support to…
unclear · top 15,000 on PyPI
colorlogAdds colored output to Python's standard…
permissive · top 1,000 on PyPI
logstash_formatterFormats Python logging output as JSON objects…
permissive · top 15,000 on PyPI