How umputun/docker-logger works
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: main.go Main · events.go Discovery · README.md Config · multiwriter.go Fan-out
Components 14
Runtime
Core daemon and its external inputs/outputs
- Docker daemon · Source of container events and logs via the Docker socket
- Container logs · Live logs read from selected containers
- Log files · Persisted local log directory with retention controls
- Syslog host · Remote host receiving forwarded syslog traffic
App packages
Main subsystems inside the Go service
- Main · Parses config and wires discovery, logging, and outputs
app/main.go - Discovery · Tracks Docker activity and decides which containers to follow
app/discovery/events.go - Logger · Formats log records and coordinates downstream writers
app/logger/logger.go - Fan-out · Broadcasts a single log stream to multiple sinks
app/logger/multiwriter.go - Syslog · Sends logs to a remote syslog endpoint with platform-specific transport
app/syslog/syslog_unix.go
Deployment
Container image and runtime wiring
- Config · CLI flags and environment variables that define runtime behavior
README.md - Docker socket · Container access path to the host Docker daemon
- Log volume · Optional mounted storage for durable local logs
docker-compose.yml - Image · Packaged Go daemon built from the repository Dockerfile
Dockerfile - Compose · Primary runtime wiring for socket, storage, and environment
docker-compose.yml
Connections 15
- 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