skillfed

logfmter

A Python package which supports global logfmt formatted logging.

logfmter v0.0.12 210.6K downloads/30d#9,490 on PyPI107
Permissive license MIT Active released

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 logfmter

uv

uv add logfmter

poetry

poetry add logfmter

Installing 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

logfmt structured loggingstdlib logging formatterstructured log outputlogfmt python loggingmachine-readable logslog formatting stdlib
structured-logginglogfmt

More Monitoring packages

tqdm

Wraps any iterable to display a real-time…

copyleft · top 100 on PyPI

opentelemetry-semantic-conventions

Provides generated Python code for…

permissive · top 100 on PyPI

opentelemetry-sdk

Provides the reference implementation of the…

permissive · top 100 on PyPI

opentelemetry-api

Provides the abstract API and interfaces for…

permissive · top 100 on PyPI

opentelemetry-exporter-otlp-proto-http

Exports OpenTelemetry observability data to an…

permissive · top 1,000 on PyPI

opentelemetry-instrumentation

Provides automatic instrumentation commands and…

permissive · top 1,000 on PyPI

daiquiri

Daiquiri simplifies Python logging…

permissive · top 15,000 on PyPI

jsonformatter

Formats Python logging output as JSON, enabling…

permissive · top 15,000 on PyPI

logging-formatter-anticrlf

A drop-in replacement for Python's standard…

permissive · top 15,000 on PyPI

logging-json

Formats Python logging records as JSON output,…

permissive · top 15,000 on PyPI

structlog

structlog is a structured logging library that…

permissive · top 1,000 on PyPI

python-json-logger

Formats Python logging output as JSON, making…

permissive · top 1,000 on PyPI

fluent-logger

Sends structured event logs from Python…

unclear · top 5,000 on PyPI

mdc

Adds Mapped Diagnostic Context (MDC) support to…

unclear · top 15,000 on PyPI

colorlog

Adds colored output to Python's standard…

permissive · top 1,000 on PyPI

logstash_formatter

Formats Python logging output as JSON objects…

permissive · top 15,000 on PyPI