Documentation
¶
Overview ¶
Package rotatelog provides a size-rotated log file writer.
Index ¶
Constants ¶
const ( DefaultMaxSize = 20 << 20 // 20 MB per active log file. DefaultBackups = 2 )
Defaults for New's maxSize and backups.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer appends to a log file and rotates it at line boundaries once the active file reaches maxSize: path.1 shifts to path.2 (and so on up to backups), path shifts to path.1, and anything older is dropped. On creation a non-empty pre-existing file is rotated away so the active file always starts fresh for each run while the previous run's tail survives as path.1. The writer never returns an error: on open or write failure it warns once on stderr and degrades to a no-op, because file logging must never take down the process it logs for.
The active file is preferentially cut at a line boundary, so it may overshoot maxSize by the remainder of the current line — but never past a hard ceiling of 2*maxSize, at which point it is force-cut mid-line. That ceiling is what keeps a runaway producer (e.g. a backend hot-looping on an error with no newline, or emitting one unbounded line) from growing the log without limit: total on-disk size stays bounded by 2*maxSize*(backups+1) whatever the producer does.