logtail

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 5 Imported by: 0

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.

func Last

func Last(path string, n int, w io.Writer) (int64, error)

Last writes the last n lines of the file at path to w and returns the size it read up to. Hand that to Follow as its offset, so lines written between the two calls are printed once rather than twice or never. n <= 0 writes nothing.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL