Categorygithub.com/go-faster/tail
modulepackage
0.4.0-alpha.2
Repository: https://github.com/go-faster/tail.git
Documentation: pkg.go.dev

# README

tail Go Reference codecov experimental

Package tail implements file tailing with fsnotify.

Fork of nxadm/tail, simplified, reworked and optimized. Currently, supports only Linux and Darwin.

go get github.com/go-faster/tail
package main

import (
	"context"
	"fmt"
	"io"
	"os"
	"time"

	"github.com/go-faster/tail"
)

func main() {
	t := tail.File("/var/log/application.txt", tail.Config{
		Follow:        true,        // tail -f
		BufferSize:    1024 * 128,  // 128 kb for internal reader buffer

		// Force polling if zero events are observed for longer than a minute.
		// Optional, just a safeguard to be sure that we are not stuck forever
		// if we miss inotify event.
		NotifyTimeout: time.Minute,

		// You can specify position to start tailing, same as Seek arguments.
		// For example, you can use the latest processed Line.Location() value.
		Location: &tail.Location{Whence: io.SeekStart, Offset: 0},
	})
	ctx := context.Background()
	// Enjoy zero allocation fast tailing with context support.
	if err := t.Tail(ctx, func(ctx context.Context, l *tail.Line) error {
		_, _ = fmt.Fprintln(os.Stdout, string(l.Data))
		return nil
	}); err != nil {
		panic(err)
	}
}

TODO

  • Tests for removing, tailing and creating events
  • Decide on Windows support

# Functions

File configures and creates new unstarted *Tailer.
NewTracker creates new custom Tracker with provided logger.

# Structs

Config is used to specify how a file must be tailed.
Line of file.
Location represents arguments to io.Seek.
Tailer implements file tailing.

# Interfaces

Tracker tracks file changes.

# Type aliases

Handler is called on each log line.