rotatelog

package
v0.0.0-...-12134b3 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package rotatelog provides a size-rotated log file writer.

Index

Constants

View Source
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.

func New

func New(path string, maxSize int64, backups int) *Writer

New opens path for writing, rotating away a non-empty previous file first. A maxSize of zero or less means DefaultMaxSize.

func (*Writer) Write

func (w *Writer) Write(data []byte) (int, error)

Write implements io.Writer. It always reports full success so a failing file never breaks the logger (or multi-writer) feeding it.

Jump to

Keyboard shortcuts

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