Documentation ¶
Overview ¶
Package logrotation provides a writer that automatically rotates logfiles if the set maximum size is reached or exceeded. Compression is enabled by default, but can be disabled if required.
Index ¶
Constants ¶
const ( // OptionReportErrors enables the error reporting channel that informs // about errors that happen in the background and are otherwise ignored OptionReportErrors = iota // OptionNoCompression disabled the compression of Archived logs. OptionNoCompression // OptionGZip enables compression using gzip OptionGZip // OptionZlib enables compression using zip OptionZlib // OptionNoSync disables the synchronous flag when opening logfiles this // can yield double speed but may lead to data loss if the system is // turned off before a flush to disk happened OptionNoSync // OptionMaxCompression sets the compression level to maximum, thereby // taking longer but achieving better compression OptionMaxCompression // OptionMinCompression sets the compression level to minimum, thereby // speeding up compression drastically while also increasing the rotated // filesize substantially OptionMinCompression )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompressorFunc ¶
CompressorFunc specifies the layout required to set custom compressors for the logfiles.
type Rotor ¶
type Rotor struct { // Permissions indicate unix file permissions to apply. By default it's // 0o600 Permissions os.FileMode // MaxFileSize is after what time the file is truncated. Default: 4 MiB MaxFileSize uint64 // Retention is how many "old" logs are kept. Default: 2. This means you // have 3 files in total: file.log, file.log.1.gz, file.log.2.gz Retention int // KeptPercent is how many % (of lines) are kept when using flowing-mode // This value is only used if retention is 0 or below. The last x% of // lines are kept and mark the starting point of the new log. Default: 5 // // Please note that this is an approximation. The percent-position will // sought and everything _after_ the next '\n' will be kept for the // rotated file. KeptPercent int // Errors is an unbuffered channel to get notified of errors while // rotating. It is only enabled when the Rotor was created with // OptionReportErrors Errors chan error // contains filtered or unexported fields }
Rotor is the struct containing all Settings, file handlers, and functions required for logrotation.
func NewRotor ¶
NewRotor generates a new Rotor with the given options overwriting the defaults. The defaults are: Permissions: 600, MaxFileSize: 4 MiB, Retention: 2, KeptPercent: 5, Compression: gzip (Default Compression)
func (*Rotor) Open ¶
Open opens (or creates) the logfile specified when setting up the Rotor. Closing this file is the responsibility of the user.
func (*Rotor) Rotate ¶
Rotate triggers a rotation, independent of whether the limit size is reached or not.
func (*Rotor) SetCompressor ¶
func (r *Rotor) SetCompressor(cf CompressorFunc, ext string)
SetCompressor allows setting a custom compression method for use when rotating