# josheppinette/python-logfmter architecture

> Architecture diagram of the GitHub repository josheppinette/python-logfmter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/josheppinette/python-logfmter
- Repository: https://github.com/josheppinette/python-logfmter

## Overview

Logfmter is a small Python logging formatter that converts standard-library LogRecord data into logfmt text. The application configures it on a logging handler; Python logging invokes it for each record, and the handler emits the returned text. Formatting covers message and extra-field extraction, configured keys/mappings/defaults, value escaping, and exception or stack information. Runtime behavior is concentrated in the sampled formatter module; configuration options and subclassing are documented in the README.

Main entry points: [`src/logfmter/formatter.py`](https://github.com/josheppinette/python-logfmter/blob/main/src/logfmter/formatter.py) (Logfmter)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_application(("Application"))
node_logging["Python logging"]
node_record["LogRecord"]
node_formatter["Logfmter<br/>[formatter.py]"]
node_field_extract["Field extraction<br/>[formatter.py]"]
node_configured_fields["Configured fields<br/>[formatter.py]"]
node_value_encoding["Logfmt encoding<br/>[formatter.py]"]
node_formatted_text["Formatted text"]
node_handler["Logging handler"]

node_application -->|"configures handler"| node_logging
node_application -->|"configures"| node_formatter
node_logging -->|"formats record"| node_formatter
node_record -->|"provides data"| node_formatter
node_formatter -->|"extracts fields"| node_field_extract
node_formatter -->|"resolves keys"| node_configured_fields
node_formatter -->|"encodes values"| node_value_encoding
node_field_extract -->|"supplies fields"| node_value_encoding
node_configured_fields -->|"supplies fields"| node_value_encoding
node_formatter -->|"returns text"| node_formatted_text
node_logging -->|"passes formatted text"| node_handler
node_handler -->|"emits"| node_formatted_text

click node_formatter "https://github.com/josheppinette/python-logfmter/blob/main/src/logfmter/formatter.py"
click node_field_extract "https://github.com/josheppinette/python-logfmter/blob/main/src/logfmter/formatter.py"
click node_configured_fields "https://github.com/josheppinette/python-logfmter/blob/main/src/logfmter/formatter.py"
click node_value_encoding "https://github.com/josheppinette/python-logfmter/blob/main/src/logfmter/formatter.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_application,node_logging,node_record,node_formatted_text toneIndigo
class node_formatter,node_field_extract,node_configured_fields,node_value_encoding toneTeal
class node_handler toneMint
```

## Components

### Other components

- **Application**
- **Python logging**
- **LogRecord**
- [Logfmter](https://github.com/josheppinette/python-logfmter/blob/main/src/logfmter/formatter.py): `src/logfmter/formatter.py`
- [Field extraction](https://github.com/josheppinette/python-logfmter/blob/main/src/logfmter/formatter.py): `src/logfmter/formatter.py`
- [Configured fields](https://github.com/josheppinette/python-logfmter/blob/main/src/logfmter/formatter.py): `src/logfmter/formatter.py`
- [Logfmt encoding](https://github.com/josheppinette/python-logfmter/blob/main/src/logfmter/formatter.py): `src/logfmter/formatter.py`
- **Formatted text**
- **Logging handler**

## Connections

- Application → Python logging: configures handler
- Application → Logfmter: configures
- Python logging → Logfmter: formats record
- LogRecord → Logfmter: provides data
- Logfmter → Field extraction: extracts fields
- Logfmter → Configured fields: resolves keys
- Logfmter → Logfmt encoding: encodes values
- Field extraction → Logfmt encoding: supplies fields
- Configured fields → Logfmt encoding: supplies fields
- Logfmter → Formatted text: returns text
- Python logging → Logging handler: passes formatted text
- Logging handler → Formatted text: emits
