eventlog

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 14 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 eventlog is the daemon's append-only event log: one JSON event per line in segment files (events.log, events.log.1, … newest first), a monotonically increasing seq that survives restarts, and an in-memory ring of the latest events that answers `since` queries without touching disk.

Retention drops whole old segments by age and by count. Nothing is fsynced per event; Close syncs the active segment.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Log

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

Log is safe for concurrent use.

func Open

func Open(base string, opts Options) (*Log, error)

Open loads (or creates) the log at base. It reads segments newest first until MaxEvents events are in memory, restores seq from the newest event and deletes segments beyond retention.

func (*Log) Any

func (l *Log) Any(pred func(*wire.Event) bool) bool

Any reports whether a retained event satisfies pred, scanning newest first without copying the ring.

func (*Log) Append

func (l *Log) Append(ev wire.Event) (wire.Event, error)

Append assigns the next seq (and Time when zero) and writes ev. On a write error the event is still assigned and kept in memory.

func (*Log) Close

func (l *Log) Close() error

Close syncs and closes the active segment.

func (*Log) Seq

func (l *Log) Seq() int64

Seq is the latest assigned seq (0 for an empty log).

func (*Log) SetRetention

func (l *Log) SetRetention(maxEvents int, maxAge time.Duration) error

SetRetention changes the count and age limits (config.set). The ring shrinks or grows (growth only fills with future events).

func (*Log) Since

func (l *Log) Since(since int64) (events []wire.Event, truncated bool)

Since returns the retained events with seq > since, oldest first, and whether some events after since were already dropped by retention. since 0 returns nothing. A since beyond the latest seq (the log was reset) reports truncated with no events.

type Options

type Options struct {
	// MaxEvents bounds the in-memory ring and the retained events.
	MaxEvents int
	// MaxAge drops events (and whole segments) older than this.
	MaxAge time.Duration
	// SegmentBytes rotates the active segment once it would exceed this size.
	SegmentBytes int64
	// SegmentAge rotates the active segment once its first event is older
	// than this, so age-based retention works on quiet hosts too.
	SegmentAge time.Duration
	// Now is the clock (tests).
	Now func() time.Time
}

Options configures a Log. Zero fields take the defaults.

Jump to

Keyboard shortcuts

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