Documentation
¶
Overview ¶
Package logtail prints the end of a log file and follows it as it grows, including across process.RotateLog's copy-then-truncate.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Follow ¶
func Follow(ctx context.Context, path string, offset int64, w io.Writer, interval time.Duration) error
Follow prints what is appended to the file at path, starting at offset, until ctx is cancelled (which returns nil: stopping is the normal way out). It polls every interval instead of using inotify/kqueue, which would be two code paths for a log that gets a few lines a second.
Two ways the file can change under it are handled. process.RotateLog copies the log aside and truncates it in place, so the size drops below our offset and the new log starts at the top: we start over from 0. "Shorter than offset" is a reliable signal because rotation only happens past 1 GiB and a log can't regrow past the old offset within one poll. And if the path is removed and recreated, we reopen it; while it is missing we keep reading the old file, which is the best we can do.
Types ¶
This section is empty.