tail

package
v0.0.0-...-fde5499 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2016 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NewLineNotify int = iota
	NewFileNotify
	TickerNotify
)

Variables

View Source
var (
	// ErrStop  tailを停止
	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)
	ReOpenDelay time.Duration // Reopen Delay

	MustExist      bool // Fail early if the file does not exist
	Poll           bool // Poll for file changes instead of using inotify
	TruncateReOpen bool // copytruncate rotate
	RenameReOpen   bool // rename rotate
	LinesChanSize  int  // Lines channel size

	// Generic IO
	NotifyInterval time.Duration // Notice interval of the elapsed time
}

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

type Line

type Line struct {
	Time       time.Time
	Text       []byte
	Filename   string
	Offset     int64
	OpenTime   time.Time
	Err        error // Error from tail
	NotifyType int
}

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

	WorkLimit chan bool

	Ctx    context.Context
	Cancel context.CancelFunc
	// contains filtered or unexported fields
}

func TailFile

func TailFile(filename string, config Config, w chan bool) (*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) Cleanup

func (tail *Tail) Cleanup()

Cleanup removes inotify watches added by the tail package. This function is meant to be invoked from a process's exit handler. Linux kernel may not automatically remove inotify watches after the process exits.

func (*Tail) Tell

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

Tell Return the file's current position, like stdio's ftell().

Jump to

Keyboard shortcuts

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