eye

package
v0.0.0-...-d6986db Latest Latest
Warning

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

Go to latest
Published: May 5, 2015 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package eye provides the internals behind the Sauron CLI tool.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DirectoryWatcher

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

DirectoryWatcher is an implementation of a Watcher capable of monitoring for changes on a directory recursively.

func NewDirectoryWatcher

func NewDirectoryWatcher(path string) (*DirectoryWatcher, error)

NewDirectoryWatcher creates a new instance of a DirectoryWatcher.

func (*DirectoryWatcher) End

func (w *DirectoryWatcher) End()

End stops the watching operation.

func (*DirectoryWatcher) Walk

func (w *DirectoryWatcher) Walk() (paths []string, err error)

Walk returns a list of all the files within the target directory.

func (*DirectoryWatcher) Watch

func (w *DirectoryWatcher) Watch(newf chan FileEvent) error

Watch starts watching for filesystem events.

type FileEvent

type FileEvent struct {
	// Name of the file affected.
	Name string
	// Path to the file, including the filename.
	Path string
	// Operation that triggerred the event.
	Op fsnotify.Op
	// Time at which the event occured.
	Time time.Time
}

FileEvent represents an event affecting a single file.

type Line

type Line struct {
	Path string
	Text string
	Time time.Time
	Err  error
}

Line contains a log line of a log file.

type LineHandler

type LineHandler func(line Line) error

LineHandler is a function capable to handle log lines.

type SimpleLogger

type SimpleLogger interface {
	Infoln(v ...interface{})
	Errorln(v ...interface{})
}

SimpleLogger should be able to handle error and info log messages.

type Trail

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

Trail represents a log trail that can be followed for new lines. In conjuction with a Watcher, a Trail is capable of monitoring existing and new files in a directory.

However, unlike the Watcher, a Trail is limited to traditional filesystems.

func NewTrail

func NewTrail(watcher Watcher) *Trail

NewTrail creates a new instance of a Trail.

func NewTrailWithOptions

func NewTrailWithOptions(watcher Watcher, options *TrailOptions) *Trail

NewTrailWithOptions creates a new instance of a Trail with a custom set of options. If any option provided is nil, it will be replaced with a safe default.

func (*Trail) End

func (t *Trail) End()

End stops watching.

func (*Trail) Follow

func (t *Trail) Follow(handler LineHandler) error

Follow starts following a trail. Every time a file is changed, the affected lines will be passed to the handler function to be proccessed. The handler function could do something as simple as writing the lines that standard output, or do more advanced things like writing to an external log server.

type TrailOptions

type TrailOptions struct {
	// Logger to be used by the trail. Messages about file events and error
	// will be sent to this logger. Use ioutil.Discard to ignore output.
	Logger SimpleLogger

	// PollChanges dictates whether the Trail should continuosly poll for
	// chastes instead of using fsnotify.
	PollChanges bool
}

TrailOptions are the different options supported by the Trail object.

type Watcher

type Watcher interface {
	Walk() (paths []string, err error)
	Watch(newf chan FileEvent) error
	End()
}

A Watcher is capable of providing a list of the current files and notify about changes in a directory. An implementation might decide whether it supports multiple directory levels (recursive) or just one level. Files also do not need to be in a traditional filesystem.

Jump to

Keyboard shortcuts

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