logrotate

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package logrotate provides a size-based rotating log writer. It implements io.Writer and io.Closer, safe for concurrent use.

Index

Constants

View Source
const (
	// DefaultMaxSize is the default maximum log file size before rotation (10 MiB).
	DefaultMaxSize = 10 * 1024 * 1024
	// DefaultMaxBackups is the default number of backup files to retain.
	DefaultMaxBackups = 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Writer

type Writer struct {
	// Path is the absolute path to the active log file.
	Path string
	// MaxSize is the maximum file size in bytes before rotation.
	// Zero or negative uses DefaultMaxSize.
	MaxSize int64
	// MaxBackups is the number of backup files to retain.
	// Zero or negative uses DefaultMaxBackups.
	MaxBackups int
	// contains filtered or unexported fields
}

Writer is an io.WriteCloser that writes to Path and rotates the file when its size exceeds MaxSize. Backup files are named Path.1, Path.2, … At most MaxBackups backup files are kept; older ones are deleted.

func (*Writer) Close

func (w *Writer) Close() error

Close closes the underlying file.

func (*Writer) Write

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

Write implements io.Writer. It rotates the underlying file when the current size plus len(p) would exceed MaxSize.

Jump to

Keyboard shortcuts

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