Categorygithub.com/powerman/tail
modulepackage
0.1.0
Repository: https://github.com/powerman/tail.git
Documentation: pkg.go.dev

# README

tail GoDoc Go Report Card CircleCI Coverage Status

Go package tail implements behaviour of tail -n 0 -F path to follow rotated log files using polling.

Most existing solutions for Go have race condition issues and occasionally may lose lines from tracked file - such bugs are hard to fix without massive changes in their architecture, so it turns out to be easier to reimplement this functionality from scratch to make it work reliable and don't lose data.

This package tries to log messages in same way as tail.

Unlike tail tool it does track renamed/removed file contents up to the moment new file will be created with original name - this ensure no data will be lost in case log rotation is done by external tool (i.e. not the one which write to log file) and thus original log file may be appended between rename/removal and reopening.

Unlike tail it does not support file truncation. While this can't work reliable, truncate support may be added in the future.

Installation

go get github.com/powerman/tail

# Functions

Follow starts tracking the path using polling.
PollDelay let you change delay between polling to save CPU.
PollTimeout let you change how long to wait before return error when failed to open or read file.

# Constants

Defaults for corresponding options.
Defaults for corresponding options.

# Structs

Tail is an io.Reader with `tail -n 0 -F path` behaviour.

# Interfaces

Logger is an interface used to log tail state changes.
Option let you change Tail behaviour.

# Type aliases

The LoggerFunc type is an adapter to allow the use of ordinary function as a logger.