LogMerge
Many log files in, one stream out — ordered by time, at about 1 GB/s.

Website ·
Releases ·
Source ·
Project page

A distributed job leaves its story scattered across driver logs, executor logs, sidecar logs,
rotated files and .gz archives. Reading them one at a time means reconstructing the timeline
in your head. LogMerge reads them all at once and writes the timeline: every line in
timestamp order, each still traceable to the file it came from, stack traces still attached to
the line that raised them.
- Point it at anything — files, directories, globs;
.gz, .bz2, .xz, .zip and
.tar.* are read in place, no extraction step
- Timestamps in many shapes — ISO 8601,
ctime, space-separated millis, with or without a
zone; normalised to one width on the way out
- Lines without a timestamp stay put — stack traces and wrapped messages follow their parent
line instead of drifting to the top or the bottom
- Know where a line came from — a per-line alias (
-a) or a --- file --- header at each
switch (-b), with glob-to-name aliases for long paths
- Fast enough to not think about — a min-heap merge with parallel prefetch, no allocation in
the hot path; about 1 GB/s from disk on an M1 Max
Quick start
logmerge ./logs -o merged.log # everything under ./logs, into one file
logmerge -t -b /var/log/app1 /var/log/app2 | less # normalised timestamps, file headers
Install
Pre-built binaries are on GitHub Releases:
# Linux (amd64)
curl -L -o logmerge https://github.com/mmdemirbas/logmerge/releases/latest/download/logmerge-linux-amd64
chmod +x logmerge
# macOS (Apple Silicon)
curl -L -o logmerge https://github.com/mmdemirbas/logmerge/releases/latest/download/logmerge-darwin-arm64
chmod +x logmerge
From source (Go 1.21+):
go install github.com/mmdemirbas/logmerge/cmd/logmerge@latest
logmerge --version confirms the install.
What comes out
Interleaved files, a file alias per block, and a stack trace kept under the line that produced it:
--- auth-service.log ---
2026-03-13 01:21:22.000000000 [INFO] User "admin" logged in from 192.168.1.5
2026-03-13 01:21:22.105000000 [DEBUG] Initializing session cache...
--- database.log ---
2026-03-13 01:21:22.500000000 [INFO] Query: SELECT * FROM users WHERE id = 1
2026-03-13 01:21:22.505000000 [ERROR] Connection timeout:
at db.connector.connect (connection.go:45)
at main.main (main.go:12)
caused by: context deadline exceeded
--- auth-service.log ---
2026-03-13 01:21:23.000000000 [INFO] Session expired for user "guest"
- Block headers (
-b): the --- name --- line marks every switch between source files.
- Orphan lines: the three trace lines carry no timestamp, so they are written right after
the
ERROR line that raised them.
- Width: timestamps are normalised to nanosecond precision, zero-padded, so columns line up.
How it works

- Discover — every path is walked, exclude patterns and aliases applied, and archives
opened in place. An entry inside an archive is addressed as
path/to/archive.tar.gz!/entry/name.log, which --alias and --exclude patterns also see.
- Prefetch — a goroutine per file parses the first timestamp so the merge can start with a
full heap. Files with no parseable timestamp are reported and skipped. Parsing state and
counters are per file, so this phase scales with cores and never takes a shared lock.
- Merge — a min-heap holds one entry per open file, keyed by the next line's timestamp,
with the timestamp stored beside the file pointer so a comparison never chases a pointer.
The earliest file is popped and streamed until its next line would overtake the heap's
next timestamp, then pushed back; each switch costs O(log k) for k files.
- Format and write — timestamp, level and alias prefixes are added and originals stripped
as requested, the
--since/--until window applied, and lines go through a buffered
writer to stdout or -o.
The things that make it fast, in one place: newline scanning uses bytes.IndexAny, which is
vectorised (NEON on arm64); the timestamp parser is straight-line code the branch predictor
learns, which measured about 6× faster than a bit-trick version; the hot path does not
allocate; and release builds are profile-guided (task build-pgo). On an M1 Max this reads
about 1.2 GB/s in memory and about 1 GB/s from disk.
Usage
CLI flags and an optional YAML file compose: flags override YAML values, and input paths are
positional.
Selecting files
logmerge /var/log/myapp # a directory
logmerge -o merged.log /var/log/app1 /var/log/app2 # several paths, into a file
logmerge -i /var/log/app1 -i /var/log/app2 # the same with -i/--in
logmerge -e "*.bak" -e "*temp*" /var/log/myapp # gitignore-style excludes
logmerge --ignore-file .logmergeignore /var/log/myapp
logmerge --ignore-archives /var/log/myapp # skip .zip .gz .tar … entirely
logmerge --follow-symlinks /var/log/myapp
logmerge --dry-run /var/log/myapp # list what would be merged
Shaping the output
logmerge -t -b /var/log/myapp # normalised timestamps + file headers
logmerge -a --alias "console.log=driver" --alias "*/worker/*.log=worker" /var/log/myapp
logmerge -t -s /var/log/myapp # replace the original timestamp
logmerge --write-level /var/log/myapp # TRACE/DEBUG/INFO/WARN/ERROR/FATAL column
logmerge -t -s --write-level --strip-level /var/log/myapp
logmerge --since 2025-01-17T13:00:00Z --until 2025-01-17T14:00:00Z /var/log/myapp
Flags
| Flag |
Effect |
-i, --in <path> |
Input file or directory; repeatable, added to positional args |
-o, --out <path> |
Output file (default: stdout) |
-t, --write-timestamp |
Prepend a normalised timestamp to each line |
-s, --strip-timestamp |
Remove the original timestamp from each line |
--write-level |
Prepend a normalised level column (TRACE … FATAL) |
--strip-level |
Remove the original level token |
-b, --write-block-alias |
Insert --- name --- when the source file changes |
-a, --write-line-alias |
Prepend the source alias to each line |
--alias <glob=name> |
Name a file or glob; repeatable |
-e, --exclude <pattern> |
Gitignore-style exclude; repeatable; ! negates |
--ignore-file <path> |
Read exclude patterns from a file |
--ignore-archives |
Skip .zip .gz .tar .rar .7z .tgz .bz2 .tbz2 .xz .txz |
--since / --until <ts> |
Keep only lines inside the window (RFC 3339) |
--dry-run |
List matched files without merging |
--follow-symlinks |
Follow symbolic links while walking directories |
--config <path> |
YAML file as the base; flags override it |
-v, --version |
Print the version |
YAML configuration
For a setup you run often. conf/example.yaml lists every field.
InputPaths:
- /var/log/myapp
- /var/log/myapp-worker
OutputFile: /tmp/merged.log
ListFilesConfig:
IgnoreArchives: true
IgnorePatterns:
- "*temp*"
- "*.bak"
FileAliases:
"console.log": "driver"
"*/worker/*.log": "worker"
MergeConfig:
WriteTimestampPerLine: true
WriteAliasPerBlock: true
MinTimestamp: "2025-01-17T00:00:00Z"
MaxTimestamp: "2025-01-18T00:00:00Z"
Archives
| Format |
Extensions |
How it is read |
| gzip |
.gz |
streamed |
| bzip2 |
.bz2 |
streamed |
| xz |
.xz |
streamed |
| zip |
.zip |
each entry as its own file |
| tar |
.tar |
entries buffered in memory |
| tar + gzip |
.tar.gz, .tgz |
streamed, entries buffered |
| tar + bzip2 |
.tar.bz2, .tbz2 |
streamed, entries buffered |
| tar + xz |
.tar.xz, .txz |
streamed, entries buffered |
Development
Go 1.21+ and, optionally, go-task.
task all # clean, test, build
task bench # benchmarks with CPU/mem/trace profiles under out/
task build-pgo # profile-guided build for this OS (after task bench)
task dist # cross-compile with PGO for darwin/linux/windows × amd64/arm64
task profile # open the CPU flame graph
See CONTRIBUTING.md.
License
MIT