# umputun/docker-logger architecture

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

- Interactive diagram: https://gitdiagram.com/umputun/docker-logger
- Repository: https://github.com/umputun/docker-logger

## Overview

1. **Overall shape**
   - This repo is a **single Go daemon** that runs in a container and tails logs from other Docker containers on the same host.
   - Its job is to **subscribe to Docker container activity**, **read container logs**, and **fan them out** to one or both destinations: **rotated local files** and **remote syslog**.

2. **Primary runtime boundary**
   - The application depends on the **host Docker daemon** through the Docker socket/host configured by `DOCKER_HOST` or the default `/var/run/docker.sock`.
   - It is deployed as a container itself, with optional **bind-mounted log storage** and optional access to a **remote syslog endpoint** over UDP.

3. **Entry point and composition**
   - `app/main.go` is the orchestrator: it parses configuration, validates mutually exclusive include/exclude rules, initializes Docker access, and wires the output sinks together.
   - This is a **composition root** rather than a heavy business-logic layer; most behavior is delegated into packages under `app/`.

4. **Docker discovery subsystem**
   - `app/discovery` is the Docker-facing subsystem.
   - Based on the file name `events.go`, it likely handles **Docker event subscription and container discovery**, deciding which containers should be tracked and when to start/stop log collection.
   - This package is where the app crosses from “static config” into **runtime container lifecycle monitoring**.

5. **Log collection and filtering flow**
   - The main data flow is: **Docker events / container list → filtering rules → container log stream**.
   - Filtering supports:
     - explicit include/exclude name lists
     - regex-based include/exclude patterns
     - mutually exclusive combinations enforced by the app
   - Only containers that match the selected policy are streamed.

6. **Log formatting and fan-out**
   - `app/logger` contains the local logging pipeline.
   - `logger.go` is the core logger abstraction; `multiwriter.go` indicates the app can **broadcast the same log entry to multiple outputs**.
   - This is the point where the stream is split to file output and/or syslog output, and where options like JSON formatting and mixing stderr into stdout are applied.

7. **File storage and rotation**
   - When file logging is enabled, the app writes to a local log directory, defaulting to `logs`.
   - The README’s `max-size`, `max-files`, and `max-age` settings imply **rotating file retention** as part of the file sink behavior.
   - In deployment, this directory is intended to be **mounted to the host** so logs survive container restarts and are accessible outside the logger container.

8. **Syslog output path**
   - `app/syslog` provides the remote syslog integration.
   - The presence of `syslog_unix.go` and `syslog_windows.go` shows platform-specific implementations, so syslog is a first-class output abstraction with OS-aware transport details.
   - This sink sends logs to a configured remote host, defaulting to UDP syslog behavior as described in the README.

9. **Configuration model**
   - The application is configured mainly through **CLI flags and environment variables**, which are mapped one-to-one in the README.
   - Important runtime choices are: Docker endpoint, file logging on/off, syslog on/off, inclusion/exclusion rules, output formatting, log retention, and timezone.
   - The configuration layer also enforces key operational constraints, especially that at least one output destination must be enabled.

10. **Deployment architecture**
   - `docker-compose.yml` is the intended production-like deployment path.
   - The container needs:
     - access to the Docker socket
     - optional volume mount for `/srv/logs`
     - optional non-root execution using `APP_UID` and `DOCKER_GID`
   - The `Dockerfile` packages the Go binary into a runnable image.

11. **Testing and test boundaries**
   - Each major package has tests and mocks:
     - `app/discovery/mocks/docker_client.go`
     - `app/logger/mocks/log_client.go`
   - This indicates the code is designed around **replaceable external adapters**, making Docker and logging outputs testable without real infrastructure.
   - The tests focus on package-level behavior rather than end-to-end orchestration only.

12. **Operational environment**
   - The app is intentionally narrow in scope: it is not a general log processing platform, but a **host-side Docker log relay**.
   - Its core dependencies are Docker, local filesystem storage, and optional syslog networking.
   - `vendor/`, `go.mod`, CI workflow, and lint config indicate a standard Go build/test pipeline with containerized delivery.

13. **What to draw in an architecture diagram**
   - Show one central service container receiving input from the **Docker daemon**.
   - Inside the service, separate:
     - discovery/filtering
     - log stream handling
     - output fan-out
   - Show two independent sinks:
     - local rotating file storage
     - remote syslog
   - Also show deployment inputs:
     - config env/flags
     - mounted log volume
     - Docker socket access

Main entry points: [`app/main.go`](https://github.com/umputun/docker-logger/blob/master/app/main.go) (Main), [`app/discovery/events.go`](https://github.com/umputun/docker-logger/blob/master/app/discovery/events.go) (Discovery), [`README.md`](https://github.com/umputun/docker-logger/blob/master/README.md) (Config), [`app/logger/multiwriter.go`](https://github.com/umputun/docker-logger/blob/master/app/logger/multiwriter.go) (Fan-out)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_runtime["Runtime"]
  node_node_docker_daemon[("Docker daemon<br/>host runtime")]
  node_node_container_streams["Container logs<br/>log stream"]
  node_node_local_store[("Log files<br/>rotating storage")]
  node_node_syslog_host[("Syslog host<br/>network endpoint")]
end

subgraph group_group_packages["App packages"]
  node_node_main["Main<br/>composition root<br/>[main.go]"]
  node_node_discovery["Discovery<br/>docker events<br/>[events.go]"]
  node_node_logger["Logger<br/>log pipeline<br/>[logger.go]"]
  node_node_multiwriter["Fan-out<br/>writer multiplexer<br/>[multiwriter.go]"]
  node_node_syslog["Syslog<br/>remote sink<br/>[syslog_unix.go]"]
end

subgraph group_group_deploy["Deployment"]
  node_node_config["Config<br/>flags/env<br/>[README.md]"]
  node_node_socket["Docker socket<br/>host mount"]
  node_node_log_volume["Log volume<br/>bind mount<br/>[docker-compose.yml]"]
  node_node_image["Image"]
  node_node_compose["Compose<br/>deployment spec<br/>[docker-compose.yml]"]
end

node_node_config -->|"configure"| node_node_main
node_node_compose -->|"run"| node_node_main
node_node_image -->|"package"| node_node_main
node_node_socket -->|"connect"| node_node_docker_daemon
node_node_main -->|"wire"| node_node_discovery
node_node_docker_daemon -->|"events"| node_node_discovery
node_node_discovery -->|"select"| node_node_container_streams
node_node_container_streams -->|"ingest"| node_node_logger
node_node_logger -->|"fan-out"| node_node_multiwriter
node_node_multiwriter -->|"write"| node_node_local_store
node_node_multiwriter -->|"write"| node_node_syslog
node_node_syslog -->|"send"| node_node_syslog_host
node_node_log_volume -->|"mount"| node_node_local_store
node_node_config -->|"rules"| node_node_discovery
node_node_config -->|"format"| node_node_logger

click node_node_main "https://github.com/umputun/docker-logger/blob/master/app/main.go"
click node_node_discovery "https://github.com/umputun/docker-logger/blob/master/app/discovery/events.go"
click node_node_logger "https://github.com/umputun/docker-logger/blob/master/app/logger/logger.go"
click node_node_multiwriter "https://github.com/umputun/docker-logger/blob/master/app/logger/multiwriter.go"
click node_node_syslog "https://github.com/umputun/docker-logger/blob/master/app/syslog/syslog_unix.go"
click node_node_config "https://github.com/umputun/docker-logger/blob/master/README.md"
click node_node_log_volume "https://github.com/umputun/docker-logger/blob/master/docker-compose.yml"
click node_node_image "https://github.com/umputun/docker-logger/tree/master/Dockerfile"
click node_node_compose "https://github.com/umputun/docker-logger/blob/master/docker-compose.yml"

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_node_docker_daemon,node_node_container_streams,node_node_local_store,node_node_syslog_host toneBlue
class node_node_main,node_node_discovery,node_node_logger,node_node_multiwriter,node_node_syslog toneAmber
class node_node_config,node_node_socket,node_node_log_volume,node_node_image,node_node_compose toneMint
```

## Components

### Runtime

Core daemon and its external inputs/outputs

- **Docker daemon**: host runtime · Source of container events and logs via the Docker socket
- **Container logs**: log stream · Live logs read from selected containers
- **Log files**: rotating storage · Persisted local log directory with retention controls
- **Syslog host**: network endpoint · Remote host receiving forwarded syslog traffic

### App packages

Main subsystems inside the Go service

- [Main](https://github.com/umputun/docker-logger/blob/master/app/main.go): composition root · Parses config and wires discovery, logging, and outputs · `app/main.go`
- [Discovery](https://github.com/umputun/docker-logger/blob/master/app/discovery/events.go): docker events · Tracks Docker activity and decides which containers to follow · `app/discovery/events.go`
- [Logger](https://github.com/umputun/docker-logger/blob/master/app/logger/logger.go): log pipeline · Formats log records and coordinates downstream writers · `app/logger/logger.go`
- [Fan-out](https://github.com/umputun/docker-logger/blob/master/app/logger/multiwriter.go): writer multiplexer · Broadcasts a single log stream to multiple sinks · `app/logger/multiwriter.go`
- [Syslog](https://github.com/umputun/docker-logger/blob/master/app/syslog/syslog_unix.go): remote sink · Sends logs to a remote syslog endpoint with platform-specific transport · `app/syslog/syslog_unix.go`

### Deployment

Container image and runtime wiring

- [Config](https://github.com/umputun/docker-logger/blob/master/README.md): flags/env · CLI flags and environment variables that define runtime behavior · `README.md`
- **Docker socket**: host mount · Container access path to the host Docker daemon
- [Log volume](https://github.com/umputun/docker-logger/blob/master/docker-compose.yml): bind mount · Optional mounted storage for durable local logs · `docker-compose.yml`
- [Image](https://github.com/umputun/docker-logger/tree/master/Dockerfile): container image · Packaged Go daemon built from the repository Dockerfile · `Dockerfile`
- [Compose](https://github.com/umputun/docker-logger/blob/master/docker-compose.yml): deployment spec · Primary runtime wiring for socket, storage, and environment · `docker-compose.yml`

## Connections

- Config → Main: configure · Flags and environment values drive startup behavior
- Compose → Main: run · Compose supplies the runtime container settings
- Image → Main: package · Dockerfile builds the executable image for the daemon
- Docker socket → Docker daemon: connect · Container reaches the host Docker API through the mounted socket
- Main → Discovery: wire · Main initializes Docker access and container selection
- Docker daemon → Discovery: events · Discovery consumes Docker events and container metadata
- Discovery → Container logs: select · Matching containers are attached for log streaming
- Container logs → Logger: ingest · Container output is handed into the logging pipeline
- Logger → Fan-out: fan-out · The logger delegates to a writer multiplexer
- Fan-out → Log files: write · One sink persists logs locally with rotation
- Fan-out → Syslog: write · Another sink forwards the same stream to syslog
- Syslog → Syslog host: send · Syslog output leaves the container over the network
- Log volume → Log files: mount · Bind mount keeps log files durable across restarts
- Config → Discovery: rules · Include/exclude and regex filters shape container selection
- Config → Logger: format · Formatting and retention settings control local logging behavior
