lotf

package module
v0.0.0-...-0b8a558 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2015 License: LGPL-2.1 Imports: 13 Imported by: 0

README

lotf

Line Oriented Tail -f. Go implementation of ``tail -f | grep [-v] -f ''

sample usage

``tail -n 10 -f testfile | grep -vf testfilter'' can be done by:

package main

import (
	"fmt"
	"github.com/chamaken/lotf"
)

func main() {
	watcher, err := lotf.NewTailWatcher()
	if err != nil {	panic(err) }

	filter, err := lotf.RegexpFilter("!testfilter")
	if err != nil { panic(err) }

	tail, err := watcher.Add("testfile", 10, filter, 10)
	if err != nil { panic(err) }

	for {
		s := tail.WaitNext()
		if s == nil { break }
		fmt.Println(*s)
	}
}

lotf command

args are multiple '<filename>:<filter file name>:<number of last lines>' in which filename is required, others are optional. filter can be inverted by putting '!' at head. so

./lotf 'testfile:!testfilter:10'

means

tail -n 10 -f testfile | grep -v -f testfilter

lotf daemon

just outputing via tcp, udp. usage is:

./lotfd [-c <conf file>]
     [-o <logfile>] [-l <loglevel>] [-p <pidfile>]
     [-n <number of last lines>]

where conf file is json format:

file: <target file>
filter: <filter file>
tcpaddr: tcp listening address
udpaddr: udp sending address
buflines: number of line in buffer

see lotfd/sample.json

requires

Documentation

Index

Constants

Variables

View Source
var ErrorEmpty = errors.New("lotf: empty")
View Source
var ErrorNegativeRead = errors.New("lotf: reader returned negative count from Read")
View Source
var ErrorStartOfFile = errors.New("lotf: no previous line")

Functions

func FileLines

func FileLines(file *os.File, nLines int) (int64, error)

FileLines sets the offset to nLines lines from the last. This does not means EOF if the file is ended with no newline.

Types

type Blockq

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

Blockq represents a push only list.

func NewBlockq

func NewBlockq(size int) (*Blockq, error)

New returns an initialized list.

func (*Blockq) Add

func (l *Blockq) Add(value interface{}) *Element

add the value at the tail and returns head Element if the limit exceeds.

func (*Blockq) AddHead

func (l *Blockq) AddHead(value interface{}) error

func (*Blockq) Done

func (l *Blockq) Done()

func (*Blockq) Head

func (l *Blockq) Head() *Element

func (*Blockq) Tail

func (l *Blockq) Tail() *Element

func (*Blockq) WaitHead

func (l *Blockq) WaitHead() *Element

blocking

type Element

type Element struct {
	Value interface{}
	// contains filtered or unexported fields
}

Element is an element in the linked list.

func (*Element) Next

func (e *Element) Next() *Element

func (*Element) WaitNext

func (e *Element) WaitNext() *Element

type Filter

type Filter interface {
	Filter(string) bool
	Reload() error
}

func RegexpFilter

func RegexpFilter(filtername string) (Filter, error)

type ReadAtSeeker

type ReadAtSeeker interface {
	ReadAt(p []byte, off int64) (n int, err error)
	Seek(offset int64, whence int) (int64, error)
}

type Tail

type Tail interface {
	Name() string
	WaitNext() *string
	Next() *string
	Reset()
	Clone() Tail
	SetFilter(Filter)
}

type TailName

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

func (*TailName) Clone

func (tail *TailName) Clone() Tail

func (*TailName) Name

func (tail *TailName) Name() string

func (*TailName) Next

func (tail *TailName) Next() *string

func (*TailName) Reset

func (tail *TailName) Reset()

func (*TailName) SetFilter

func (tail *TailName) SetFilter(filter Filter)

func (*TailName) String

func (tail *TailName) String() string

func (*TailName) WaitNext

func (tail *TailName) WaitNext() *string

type TailReader

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

func NewTailReader

func NewTailReader(rd ReadAtSeeker) (*TailReader, error)

NewTailReader returns a new TailReader whose buffer has the default size.

func NewTailReaderSize

func NewTailReaderSize(rd ReadAtSeeker, size int) (*TailReader, error)

func (*TailReader) PrevBuffered

func (b *TailReader) PrevBuffered() int

func (*TailReader) PrevBytes

func (b *TailReader) PrevBytes(delim byte) (line []byte, err error)

func (*TailReader) PrevSlice

func (b *TailReader) PrevSlice(delim byte) (line []byte, err error)

func (*TailReader) Rewind

func (b *TailReader) Rewind()

func (*TailReader) String

func (b *TailReader) String() string

func (*TailReader) Tell

func (b *TailReader) Tell() int64

type TailWatcher

type TailWatcher struct {
	Error <-chan error
	// contains filtered or unexported fields
}

func NewTailWatcher

func NewTailWatcher() (*TailWatcher, error)

TailWatcher constructor

func (*TailWatcher) Add

func (tw *TailWatcher) Add(pathname string, maxline int, filter Filter, lines int) (Tail, error)

func (*TailWatcher) Close

func (tw *TailWatcher) Close() error

func (*TailWatcher) Lookup

func (tw *TailWatcher) Lookup(pathname string) (Tail, error)

func (*TailWatcher) Remove

func (tw *TailWatcher) Remove(pathname string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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