tail

package module
v0.0.0-...-c35925b Latest Latest
Warning

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

Go to latest
Published: Oct 27, 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.

Log rotation

Tail comes with full support for truncation/move detection as it is designed to work with log rotation tools.

Installing

go get github.com/ActiveState/tail/...

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 {
	// File-specifc
	Location  *SeekInfo // Seek to this location before tailing
	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
	LimitRate int64     // Maximum read rate (lines per second)

	// Generic IO
	Follow      bool // Continue looking for new lines (tail -f)
	MaxLineSize int  // If non-zero, split longer lines into multiple lines
}

Config is used to specify how a file must be tailed.

type Line

type Line struct {
	Text string
	Time time.Time
	Err  error // Error from tail
}

type RateMonitor

type RateMonitor struct {
	// contains filtered or unexported fields
}

RateMonitor is a naive rate monitor that monitors the number of items processed in the current second.

func (*RateMonitor) Tick

func (r *RateMonitor) Tick(unixTime int64) int64

type SeekInfo

type SeekInfo struct {
	Offset int64
	Whence int // os.SEEK_*
}

SeekInfo represents arguments to `os.Seek`

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. Output stream is made available via the `Tail.Lines` channel. To handle errors during tailing, invoke the `Wait` or `Err` method after finishing reading from the `Lines` channel.

func (*Tail) Stop

func (tail *Tail) Stop() error

Stop stops the tailing activity.

func (*Tail) Tell

func (tail *Tail) Tell() (offset int64, err error)

Return the file's current position, like stdio's ftell(). But this value is not very accurate. it may readed one line in the chan(tail.Lines), so it may lost one line.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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