Home
Softono
tail

tail

Open source MIT Go
400
Stars
80
Forks
28
Issues
6
Watchers
1 year
Last Commit

About tail

nxadm/tail is a Go package that emulates the BSD tail program, enabling applications to read from continuously updated files (tail -f). It supports file truncation and movement detection, making it suitable for use with log rotation tools. The library works across all Go-supported operating systems, including Linux, BSD, macOS, and Windows, and requires Go 1.12 or newer. It is an actively maintained drop-in replacement for the abandoned hpcloud/tail library, continuing development with updated dependencies, improved documentation, and bug fixes. Users install it via go get and can easily follow log files by leveraging APIs for tailing files, reading new lines as they appear, and reopening files after rotation. Example usage includes monitoring log files such as nginx access or error logs.

Platforms

Web Self-hosted

Languages

Go

Links

Go Reference ci FreeBSD

tail functionality in Go

nxadm/tail provides a Go library that emulates the features of the BSD tail program. The library comes with full support for truncation/move detection as it is designed to work with log rotation tools. The library works on all operating systems supported by Go, including POSIX systems like Linux, *BSD, MacOS, and MS Windows. Go 1.12 is the oldest compiler release supported.

A simple example:

// Create a tail
t, err := tail.TailFile(
    "/var/log/nginx.log", tail.Config{Follow: true, ReOpen: true})
if err != nil {
    panic(err)
}

// Print the text of each received line
for line := range t.Lines {
    fmt.Println(line.Text)
}

See API documentation.

Installing

go get github.com/nxadm/tail/...

History

This project is an active, drop-in replacement for the abandoned Go tail library at hpcloud. Next to addressing open issues/PRs of the original project, nxadm/tail continues the development by keeping up to date with the Go toolchain (e.g. go modules) and dependencies, completing the documentation, adding features and fixing bugs.

Examples

Examples, e.g. used to debug an issue, are kept in the examples directory.