Documentation ¶
Overview ¶
Package rotator implements a simple logfile rotator. Logs are read from an io.Reader and are written to a file until they reach a specified size. The log is then truncated and (by default) gzipped to another file or compressed with a user-configurable compression scheme.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Compressor ¶ added in v1.1.0
type Compressor interface { io.WriteCloser Reset(io.Writer) Flush() error }
Compressor writes a compressed stream to an underlying writer. The underlying writer and the compression state is reset for each rotated file.
type Rotator ¶
type Rotator struct {
// contains filtered or unexported fields
}
A Rotator writes input to a file, splitting it up into gzipped chunks once the filesize reaches a certain threshold.
func New ¶
New returns a new Rotator. The rotator can be used either by reading input from an io.Reader by calling Run, or writing directly to the Rotator with Write.
func (*Rotator) Run ¶
Run begins reading lines from the reader and rotating logs as necessary. Run should not be called concurrently with Write.
Prefer to use Rotator as a writer instead to avoid unnecessary scanning of input, as this job is better handled using io.Pipe.
func (*Rotator) SetCompressor ¶ added in v1.1.0
func (r *Rotator) SetCompressor(zw Compressor, suffix string)
SetCompressor changes the algorithm or compression parameters used to compress rotated log files. By default, compression is performed using gzip with default parameters and a "gz" suffix. Setting a nil compressor disables compression.
SetCompressor is not concurrent safe and must be called before the Rotator is run.