rotate

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 8 Imported by: ? 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileConfig

type FileConfig struct {
	Dir        string     `yaml:"dir"`
	Name       string     `yaml:"name"`
	MaxBytes   int64      `yaml:"max_bytes"`
	Daily      bool       `yaml:"daily"`
	MaxBackups int        `yaml:"max_backups"`
	MaxAgeDays int        `yaml:"max_age_days"`
	Sync       SyncPolicy `yaml:"sync"`
}

FileConfig is the shared YAML block for logger and msglog file output.

func (FileConfig) Enabled

func (c FileConfig) Enabled() bool

Enabled reports whether file output is configured (non-empty directory).

func (FileConfig) ToPolicy

func (c FileConfig) ToPolicy(ext string) Policy

ToPolicy converts FileConfig into a runtime Policy. ext is fixed by the caller ("log" or "jsonl") and is not configurable.

type Policy

type Policy struct {
	Dir        string     // output directory
	BaseName   string     // filename prefix, e.g. "seq" / "msg"
	Ext        string     // extension without dot, e.g. "log" / "jsonl"
	MaxBytes   int64      // size trigger; <=0 disables
	Daily      bool       // UTC day-boundary trigger
	MaxBackups int        // max retained files (0 = unlimited)
	MaxAgeDays int        // max age in days (0 = no age-based deletion)
	Sync       SyncPolicy // durability policy; empty treated as SyncRotate
}

Policy describes runtime rotation rules for one output file. Date and size are OR conditions: either trigger causes a rollover.

type SyncPolicy

type SyncPolicy string

SyncPolicy controls how aggressively writes are flushed to durable storage.

const (
	// SyncNone relies on write(2) into the kernel page cache only.
	// Survives process crash; does not survive power loss.
	SyncNone SyncPolicy = "none"
	// SyncRotate fsyncs at each rotation boundary (default).
	SyncRotate SyncPolicy = "rotate"
	// SyncPeriodic fsyncs on an external cadence (e.g. observer 1s tick).
	SyncPeriodic SyncPolicy = "periodic"
	// SyncEach fsyncs after every Write. Strongest and most expensive.
	SyncEach SyncPolicy = "each"
)

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer is an io.Writer that rotates on UTC date and/or size. Steady-state Write is lock-free (atomic active pointer + size); the mutex is taken only on the rare rotation path. Writes go straight to *os.File with O_APPEND (no userspace buffering) so a process crash cannot lose a completed write that already returned.

func NewWriter

func NewWriter(pol Policy) (*Writer, error)

NewWriter creates a Writer and opens (or appends to) today's active file.

func (*Writer) ActiveName

func (rw *Writer) ActiveName() string

ActiveName returns the basename of the current active file (for tests/cleanup).

func (*Writer) Close

func (rw *Writer) Close() error

Close syncs and closes the active file and any retiring fds.

func (*Writer) Policy

func (rw *Writer) Policy() Policy

Policy returns a copy of the writer policy.

func (*Writer) Sync

func (rw *Writer) Sync() error

Sync fsyncs the active file. Used by SyncPeriodic callers.

func (*Writer) Write

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

Write appends p to the active file, rotating first if needed.

Jump to

Keyboard shortcuts

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