rotator

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2017 License: BSD-2-Clause Imports: 9 Imported by: 474

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 gzipped to another file and truncated.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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