github.com/ernado/tail
go get github.com/ernado/tail

github.com/ernado/tail

tail files with inotify

by go-faster

v0.1.0-alpha.1 (see all)License:MIT
go get github.com/ernado/tail
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

GitHub Stars

12

LAST COMMIT

3mos ago

MAINTAINERS

0

CONTRIBUTORS

2

OPEN ISSUES

2

OPEN PRs

0
VersionTagPublished
v0.1.0-alpha.1.0.20211123085754-a5c938cfc6d2
5mos ago
v0.1.0-alpha.1
5mos ago
v0.0.0-20211017211849-e3d8d40d8e77
7mos ago
v0.0.0-20211017174706-4131268f1a38
7mos ago
No alternatives found
No tutorials found
Add a tutorial