tail: github.com/hpcloud/tail Index | Files | Directories

package tail

import "github.com/hpcloud/tail"


Package Files

tail.go tail_posix.go


var (
    // DefaultLogger is used when Config.Logger == nil
    DefaultLogger = log.New(os.Stderr, "", log.LstdFlags)
    // DiscardingLogger can be used to disable logging output
    DiscardingLogger = log.New(ioutil.Discard, "", 0)
var (
    ErrStop = errors.New("tail should now stop")

func OpenFile Uses

func OpenFile(name string) (file *os.File, err error)

type Config Uses

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
    Pipe        bool      // Is a named pipe (mkfifo)
    RateLimiter *ratelimiter.LeakyBucket

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

    // Logger, when nil, is set to tail.DefaultLogger
    // To disable logging: set field to tail.DiscardingLogger
    Logger logger

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

type Line Uses

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

func NewLine Uses

func NewLine(text string) *Line

NewLine returns a Line with present time.

type SeekInfo Uses

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

SeekInfo represents arguments to `os.Seek`

type Tail Uses

type Tail struct {
    Filename string
    Lines    chan *Line

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

func TailFile Uses

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) Cleanup Uses

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) Stop Uses

func (tail *Tail) Stop() error

Stop stops the tailing activity.

func (*Tail) StopAtEOF Uses

func (tail *Tail) StopAtEOF() error

StopAtEOF stops tailing as soon as the end of the file is reached.

func (*Tail) Tell Uses

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.


ratelimiterPackage ratelimiter implements the Leaky Bucket ratelimiting algorithm with memcached and in-memory backends.
vendor/gopkg.in/fsnotify/fsnotify.v1Package fsnotify provides a platform-independent interface for file system notifications.
vendor/gopkg.in/tomb.v1The tomb package offers a conventional API for clean goroutine termination.

Package tail imports 14 packages (graph) and is imported by 202 packages. Updated 2020-05-12. Refresh now. Tools for package owners.