Documentation ¶
Overview ¶
Package tail provides tools to tail files in go. It also provides tools to watch a file for new lines, or to watch whole directories for new content.
Index ¶
- func FollowFile(ctx context.Context, opts ...TailFileOpt)
- func FollowFiles(ctx context.Context, opts ...TailFilesOpt)
- func TailFile(ctx context.Context, opts ...TailFileOpt) (err error)
- func TailFiles(ctx context.Context, opts ...TailFilesOpt)
- type FileError
- type FileErrorID
- type FileLine
- type FileLineID
- type FilterFunc
- type TailFileOpt
- type TailFilesOpt
- type Tailor
- func (t *Tailor) AddDirectory(dirname string, filter FilterFunc) (uid ulid.ULID, err error)
- func (t *Tailor) AddRecursiveDirectory(dirname string, filter FilterFunc) (uid ulid.ULID, err error)
- func (t *Tailor) Close()
- func (t *Tailor) CloseOnContext(ctx context.Context)
- func (t *Tailor) NDirectories() uint64
- func (t *Tailor) NFiles() uint64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FollowFile ¶
func FollowFile(ctx context.Context, opts ...TailFileOpt)
FollowFile watches a single file for new lines and reports the new lines to a string channel given by options. FollowFile does not return immediatly. The context can be used to stop following. If the context is canceled, eventually the given channels will be closed. If given, the results string channel must be consumed by the client. If given, the error channel must be consumed by the client.
func FollowFiles ¶
func FollowFiles(ctx context.Context, opts ...TailFilesOpt)
FollowFiles watches a list of files for new lines, like tail -F would do, and report the new lines to a FileLine channel given by options. FollowFiles does not return immediatly. The context can be used to stop following. If the context is canceled, eventually the given channels will be closed. If given, the results FileLine channel must be consumed by the client. If given, the error channel must be consumed by the client.
func TailFile ¶
func TailFile(ctx context.Context, opts ...TailFileOpt) (err error)
TailFile returns the N last lines of the given file to a string channel. TailFile returns immediatly. The context can be used to stop the tailing. The given channels will be closed at the end of the tailing or after the context has been canceled. If given, the string channel must be consumed by the client. If given, the error channel must be consumed by the client.
func TailFiles ¶
func TailFiles(ctx context.Context, opts ...TailFilesOpt)
TailFiles returns the N last lines of the given files to a FileLine channel. TailFiles returns immediatly. The context can be used to stop the tailing. The given channels will be closed at the end of the tailing or after the context has been canceled. If given, the FileLine channel must be consumed by the client. If given, the error channel must be consumed by the client.
Types ¶
type FileErrorID ¶
type FileLineID ¶
type FilterFunc ¶
FilterFunc is the type of filter functions.
type TailFileOpt ¶
type TailFileOpt func(opts *tailFileOpts)
TailFileOpt is the type for the options of TailFile and FollowFile
func ErrorChan ¶
func ErrorChan(errors chan error) TailFileOpt
ErrorChan is the TailFile and FollowFile option to set the channel where to send errors
func Filename ¶
func Filename(filename string) TailFileOpt
Filename is the TailFile and FollowFile option to set the file to tail/watch
func LinesChan ¶
func LinesChan(results chan []byte) TailFileOpt
LinesChan is the TailFile and FollowFile option to set the channel that will be used to send resulting lines
func MErrorChan ¶
func MErrorChan(errors chan error) TailFileOpt
MErrorChan is the TailFiles and FollowFiles option to set the channel where to send errors
func NLines ¶
func NLines(nbLines int) TailFileOpt
NLines is the TailFile and FollowFile option to set the number of lines to display from the end of files
func SleepPeriod ¶
func SleepPeriod(period time.Duration) TailFileOpt
SleepPeriod is the TailFile and FollowFile option to set the pause period between pollings in poller mode.
type TailFilesOpt ¶
type TailFilesOpt func(opts *tailFilesOpts)
TailFilesOpt is the type for the options of TailFiles and FollowFiles
func MFilename ¶
func MFilename(filename string) TailFilesOpt
MFilename is the TailFiles and FollowFiles option to add a file to the list of files to tail/watch.
func MFilenames ¶
func MFilenames(filenames []string) TailFilesOpt
MFilenames is the TailFiles and FollowFiles option to set the list of files to tail/watch.
func MLinesChan ¶
func MLinesChan(results chan FileLine) TailFilesOpt
MLinesChan is the TailFiles and FollowFiles option to set the channel that will be used to send resulting lines
func MNLines ¶
func MNLines(nbLines int) TailFilesOpt
MNLines is the TailFiles and FollowFiles option to set the number of lines to display from the end of files
func MSleepPeriod ¶
func MSleepPeriod(period time.Duration) TailFilesOpt
MSleepPeriod is the TailFiles and FollowFiles option to set the pause period between pollings in poller mode.
type Tailor ¶
type Tailor struct {
// contains filtered or unexported fields
}
Tailor can be used to monitor whole directories and report new lines in files that live inside the directories.
func NewTailor ¶
func NewTailor(results chan FileLineID, errors chan error) (t *Tailor, err error)
NewTailor builds a *Tailor.
The detected new lines will be sent in the results channel. Errors that may happen in processing will be sent to errors.
Both results and errors channels can be nil. If one of them is not nil, it must be consumed by the client.
func (*Tailor) AddDirectory ¶
AddDirectory tells the Tailor to watch globally a directory. The existing files and the new created files directly under dirname will be monitored for new content. Sub-directories are not added. The filter is a function to select which files to monitor, based on the name of a file (relative name of the file in its parent directory).
func (*Tailor) AddRecursiveDirectory ¶
func (t *Tailor) AddRecursiveDirectory(dirname string, filter FilterFunc) (uid ulid.ULID, err error)
AddRecursiveDirectory tells the Tailor to watch globally and recursively a directory. The existing files and the new created files inside dirname will be monitored for new content. Sub-directories of dirname are added too. The filter is a function to select which files to monitor, based on the name of a file (relative name of the file relative to the top-most directory).
func (*Tailor) Close ¶
func (t *Tailor) Close()
Close stops the Tailor. New content will not be detected anymore. Eventually the results and errors channels will be closed.
func (*Tailor) CloseOnContext ¶
CloseOnContext closes the Tailor when the given context is canceled.