Skip to content

Follow files across rotation and truncation - #1

Merged
autoantohaki merged 2 commits into
mainfrom
feat/follow
Oct 21, 2026
Merged

autoantohaki merged 2 commits into
mainfrom
feat/follow

Conversation

@autoantohaki

Copy link
Copy Markdown
Member

Before: relay-logs printed a file once and exited, so watching a live log meant falling back to tail -f.

After: relay-logs -f app.log prints the last 10 lines and then every line appended to the file, colored by level. -n sets how many lines to start with, and several files can be followed at once with their lines interleaved as they arrive.

The follower only prints complete lines, so a line that is still being written is never split. It starts over when a file is truncated, reads the new file from its first line after log rotation, and waits for a file that does not exist yet.

How: followFile polls the file's size and identity (device, inode, birth time) and reads only the new byte range through the existing LineSplitter. readLastLines reads backwards in 64 KB blocks to find the starting point. mergeSources races the sources' iterators so one quiet or failing file does not hold up the others. Tests cover tail, partial lines, truncation, rotation, late files, and merging.

@autoantohaki
autoantohaki merged commit a152531 into main Oct 21, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant