rotator

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: BSD-2-Clause Imports: 9 Imported by: 516

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

func New(filename string, thresholdKB int64, tee bool, maxRolls int) (*Rotator, error)

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) Close

func (r *Rotator) Close() error

Close closes the output logfile.

func (*Rotator) Run

func (r *Rotator) Run(reader io.Reader) error

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.

func (*Rotator) Write

func (r *Rotator) Write(p []byte) (n int, err error)

Write implements the io.Writer interface for Rotator. If p ends in a newline and the file has exceeded the threshold size, the file is rotated.

Jump to

Keyboard shortcuts

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