# mengrao/fmtlog architecture

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

- Interactive diagram: https://gitdiagram.com/mengrao/fmtlog
- Repository: https://github.com/mengrao/fmtlog

## Overview

fmtlog is a C++ asynchronous logging library. Applications submit formatted log calls into per-thread queues; a caller-driven poller or optional background polling thread collects messages in time order, formats headers and messages, then writes to stdout or a configured file and can invoke a callback. The graph also includes runtime filtering, rate-limited logging, and timestamp calibration. Relationships for documented capabilities rely on the README; sampled source excerpts show the API macros, queue and polling behavior, but do not expose every implementation detail.

Main entry points: [`fmtlog-inl.h`](https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h) (Polling), [`fmtlog.h`](https://github.com/mengrao/fmtlog/blob/main/fmtlog.h) (Logging API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_submit["Log submission"]
  node_api["Logging API<br/>[fmtlog.h]"]
  node_filter["Level filtering<br/>[fmtlog.h]"]
  node_rate["Rate limiting<br/>[fmtlog.h]"]
  node_producer["Log producer<br/>[fmtlog-inl.h]"]
  node_queues["Thread queues<br/>[fmtlog.h]"]
end

subgraph group_process["Collection and formatting"]
  node_polling["Polling<br/>[fmtlog-inl.h]"]
  node_time["Timestamp calibration<br/>[fmtlog.h]"]
  node_ordering["Time ordering<br/>[fmtlog-inl.h]"]
  node_formatting["Message formatting<br/>[fmtlog-inl.h]"]
  node_headers["Header patterns<br/>[fmtlog-inl.h]"]
  node_poller["Background poller<br/>[fmtlog-inl.h]"]
end

subgraph group_output["Output and controls"]
  node_sink["File and stdout<br/>[fmtlog-inl.h]"]
  node_callback["Log callback<br/>[fmtlog-inl.h]"]
  node_flush["Buffer flushing<br/>[fmtlog-inl.h]"]
end

node_application(("Application"))
node_fmt["fmt library"]

node_application -->|"logs through"| node_api
node_api -->|"checks level"| node_filter
node_api -->|"limits frequency"| node_rate
node_api -->|"submits message"| node_producer
node_producer -->|"enqueues"| node_queues
node_application -->|"polls"| node_polling
node_poller -->|"runs periodically"| node_polling
node_polling -->|"collects messages"| node_queues
node_polling -->|"calibrates clock"| node_time
node_polling -->|"merges by time"| node_ordering
node_polling -->|"processes messages"| node_formatting
node_formatting -->|"adds header"| node_headers
node_formatting -->|"formats with"| node_fmt
node_polling -->|"writes output"| node_sink
node_polling -->|"invokes callback"| node_callback
node_polling -->|"flushes buffer"| node_flush
node_flush -->|"writes buffered data"| node_sink
node_application -.->|"starts optionally"| node_poller

click node_api "https://github.com/mengrao/fmtlog/blob/main/fmtlog.h"
click node_filter "https://github.com/mengrao/fmtlog/blob/main/fmtlog.h"
click node_rate "https://github.com/mengrao/fmtlog/blob/main/fmtlog.h"
click node_producer "https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h"
click node_queues "https://github.com/mengrao/fmtlog/blob/main/fmtlog.h"
click node_polling "https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h"
click node_time "https://github.com/mengrao/fmtlog/blob/main/fmtlog.h"
click node_ordering "https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h"
click node_formatting "https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h"
click node_headers "https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h"
click node_sink "https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h"
click node_callback "https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h"
click node_flush "https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h"
click node_poller "https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h"

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_api,node_filter,node_rate,node_producer,node_queues toneBlue
class node_polling,node_time,node_ordering,node_formatting,node_headers,node_poller toneAmber
class node_sink,node_callback,node_flush toneMint
class node_application,node_fmt toneIndigo
```

## Components

### Log submission

- [Logging API](https://github.com/mengrao/fmtlog/blob/main/fmtlog.h): `fmtlog.h`
- [Level filtering](https://github.com/mengrao/fmtlog/blob/main/fmtlog.h): `fmtlog.h`
- [Rate limiting](https://github.com/mengrao/fmtlog/blob/main/fmtlog.h): `fmtlog.h`
- [Log producer](https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h): `fmtlog-inl.h`
- [Thread queues](https://github.com/mengrao/fmtlog/blob/main/fmtlog.h): `fmtlog.h`

### Collection and formatting

- [Polling](https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h): `fmtlog-inl.h`
- [Timestamp calibration](https://github.com/mengrao/fmtlog/blob/main/fmtlog.h): `fmtlog.h`
- [Time ordering](https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h): `fmtlog-inl.h`
- [Message formatting](https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h): `fmtlog-inl.h`
- [Header patterns](https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h): `fmtlog-inl.h`
- [Background poller](https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h): `fmtlog-inl.h`

### Output and controls

- [File and stdout](https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h): `fmtlog-inl.h`
- [Log callback](https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h): `fmtlog-inl.h`
- [Buffer flushing](https://github.com/mengrao/fmtlog/blob/main/fmtlog-inl.h): `fmtlog-inl.h`

### Other components

- **Application**
- **fmt library**

## Connections

- Application → Logging API: logs through (evidence: `README.md`)
- Logging API → Level filtering: checks level (evidence: `fmtlog.h`)
- Logging API → Rate limiting: limits frequency (evidence: `fmtlog.h`)
- Logging API → Log producer: submits message (evidence: `fmtlog.h`)
- Log producer → Thread queues: enqueues (evidence: `fmtlog-inl.h`)
- Application → Polling: polls (evidence: `README.md`)
- Background poller → Polling: runs periodically (evidence: `fmtlog-inl.h`)
- Polling → Thread queues: collects messages (evidence: `fmtlog-inl.h`)
- Polling → Timestamp calibration: calibrates clock (evidence: `fmtlog-inl.h`)
- Polling → Time ordering: merges by time (evidence: `fmtlog-inl.h`)
- Polling → Message formatting: processes messages (evidence: `fmtlog-inl.h`)
- Message formatting → Header patterns: adds header (evidence: `README.md`)
- Message formatting → fmt library: formats with (evidence: `README.md`)
- Polling → File and stdout: writes output (evidence: `README.md`)
- Polling → Log callback: invokes callback (evidence: `README.md`)
- Polling → Buffer flushing: flushes buffer (evidence: `README.md`)
- Buffer flushing → File and stdout: writes buffered data (evidence: `README.md`)
- Application → Background poller: starts optionally (evidence: `README.md`)
