tail

package module
Version: v0.0.0-...-d3c80d3 Latest Latest
Warning

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

Go to latest
Published: May 29, 2013 License: MIT Imports: 8 Imported by: 0

README

Go package for tail-ing files

A Go package striving to emulate the features of the BSD tail program.

t, err := tail.TailFile("/var/log/nginx.log", tail.Config{Follow: true})
for line := range t.Lines {
    fmt.Println(line.Text)
}

See API documentation.

Installing

go get github.com/ActiveState/tail

Building

To build and test the package,

make test

To build the toy command-line program gotail,

cd cmd/gotail
make
./gotail -h

TODO

  • Support arbitrary values for Location

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStop = fmt.Errorf("tail should now stop")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Location    int  // Tail from last N lines (tail -n)
	Follow      bool // Continue looking for new lines (tail -f)
	ReOpen      bool // Reopen recreated files (tail -F)
	MustExist   bool // Fail early if the file does not exist
	Poll        bool // Poll for file changes instead of using inotify
	MaxLineSize int  // If non-zero, split longer lines into multiple lines
}

Tail configuration

type Line

type Line struct {
	Text string
	Time time.Time
}

type Tail

type Tail struct {
	Filename string
	Lines    chan *Line
	Config

	tomb.Tomb // provides: Done, Kill, Dying
	// contains filtered or unexported fields
}

func TailFile

func TailFile(filename string, config Config) (*Tail, error)

TailFile begins tailing the file with the specified configuration. Output stream is made available via the `Tail.Lines` channel. To handle errors during tailing, invoke the `Wait` method after finishing reading from the `Lines` channel.

func (*Tail) Stop

func (tail *Tail) Stop() error

Stop stops the tailing activity.

Source Files

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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