logbuf

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package logbuf keeps the agent's most recent log output in memory so it can be read back after the fact, there being no stderr to read when the agent is started from a desktop launcher.

Index

Constants

View Source
const DefaultCapacity = 5000

DefaultCapacity is the number of entries kept when none is specified.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	// Seq is monotonic in write order, so a reader can ask for only what
	// followed the last entry it saw.
	Seq     uint64    `json:"seq"`
	Time    time.Time `json:"time"`
	Level   Level     `json:"level"`
	Source  string    `json:"source,omitempty"` // logger prefix, e.g. "[agent]"
	Message string    `json:"message"`
}

Entry is one captured log line.

type Level

type Level string

Level is the severity inferred for a log line. The agent logs without levels, so this is recovered from the text — good enough to drive a filter, not to be relied on for control flow.

const (
	LevelInfo  Level = "info"
	LevelWarn  Level = "warn"
	LevelError Level = "error"
)

type Ring

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

Ring is a bounded, concurrency-safe buffer of the most recent log entries. It implements io.Writer and fans each entry out to subscribers.

func New

func New(capacity int) *Ring

New returns a Ring holding up to capacity entries. Non-positive capacity falls back to DefaultCapacity.

func (*Ring) Entries

func (r *Ring) Entries() []Entry

Entries returns the buffered entries, oldest first.

func (*Ring) Len

func (r *Ring) Len() int

Len returns the number of entries currently held.

func (*Ring) Since

func (r *Ring) Since(seq uint64) []Entry

Since returns the buffered entries with Seq greater than seq, oldest first. A caller whose seq predates the ring receives only what survives.

func (*Ring) Subscribe

func (r *Ring) Subscribe(buffer int) (<-chan Entry, func())

Subscribe returns a channel of entries recorded from now on and a function that closes it. Entries arriving while the buffer is full are dropped; track Seq and backfill with Since if none may be missed.

func (*Ring) Write

func (r *Ring) Write(p []byte) (int, error)

Write implements io.Writer, recording each complete line as an entry. It never reports an error — that would propagate into the code trying to log.

Jump to

Keyboard shortcuts

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