tail

package module
v2.10.6-bug100770-inot... Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2013 License: MIT Imports: 10 Imported by: 838

README

Tail implementation in Go

A Go package striving to emulate the BSD tail program.

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

Installing

go get github.com/ActiveState/tail

Building

To build and test the package,

make test

To build the command-line program gotail,

cd cmd/gotail
make
./gotail -h

TODO

  • Support arbitrary values for Location

Documentation

Overview

TODO: avoid creating two instances of the fsnotify.Watcher struct

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cleanup

func Cleanup()

Cleanup removes open inotify watchers (as the Linux kernel doesn't do it upon process exit).

Types

type Config

type Config struct {
	Location    int  // -n
	Follow      bool // -f
	ReOpen      bool // -F
	MustExist   bool // if false, wait for the file to exist before beginning to tail.
	Poll        bool // if true, do not use inotify but use polling
	MaxLineSize int  // if > 0, limit the line size (rest of the line would be returned as next lines)
}

type FileWatcher

type FileWatcher interface {
	BlockUntilExists() error
	ChangeEvents() chan bool
}

type InotifyFileWatcher

type InotifyFileWatcher struct {
	Filename string
}

FileWatcher monitors file-level events

func NewInotifyFileWatcher

func NewInotifyFileWatcher(filename string) *InotifyFileWatcher

func (*InotifyFileWatcher) BlockUntilExists

func (fw *InotifyFileWatcher) BlockUntilExists() error

BlockUntilExists blocks until the file comes into existence. If the file already exists, then block until it is created again.

func (*InotifyFileWatcher) ChangeEvents

func (fw *InotifyFileWatcher) ChangeEvents() chan bool

ChangeEvents returns a channel that gets updated when the file is ready to be read.

type InotifyTracker

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

func NewInotifyTracker

func NewInotifyTracker() *InotifyTracker

func (*InotifyTracker) CloseAll

func (t *InotifyTracker) CloseAll()

func (*InotifyTracker) CloseWatcher

func (t *InotifyTracker) CloseWatcher(w *fsnotify.Watcher) (err error)

func (*InotifyTracker) NewWatcher

func (t *InotifyTracker) NewWatcher() (*fsnotify.Watcher, error)

type Line

type Line struct {
	Text string
	Time time.Time
}

type PollingFileWatcher

type PollingFileWatcher struct {
	Filename string
}

FileWatcher monitors file-level events

func NewPollingFileWatcher

func NewPollingFileWatcher(filename string) *PollingFileWatcher

func (*PollingFileWatcher) BlockUntilExists

func (fw *PollingFileWatcher) BlockUntilExists() error

BlockUntilExists blocks until the file comes into existence. If the file already exists, then block until it is created again.

func (*PollingFileWatcher) ChangeEvents

func (fw *PollingFileWatcher) ChangeEvents() chan bool

ChangeEvents returns a channel that gets updated when the file is ready to be read.

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 channels the lines of a logfile along with timestamp. If end is true, channel only newly added lines. If retry is true, tail the file name (not descriptor) and retry on file open/read errors. func TailFile(filename string, maxlinesize int, end bool, retry bool, useinotify bool) (*Tail, error) {

func (*Tail) Stop

func (tail *Tail) Stop() error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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