logring

package
v0.2.0-dev.4 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0 Imports: 7 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 logring keeps the panel's last log records in memory and lets the owner change the level while it runs. Handler wraps the process's slog handler: every record the current level lets through goes to the ring and on to the wrapped handler. The ring is for the panel's own diagnostics (the panel_logs RPC and MCP tool); it holds raw records, so a reader must scrub them (internal/panel/ops does) before they leave the process.

Index

Constants

View Source
const DefaultCapacity = 5000

DefaultCapacity is how many records the ring keeps.

Variables

This section is empty.

Functions

func LevelName

func LevelName(l slog.Level) string

LevelName is the name ParseLevel reads back.

func ParseLevel

func ParseLevel(s string) (slog.Level, bool)

ParseLevel reads "debug", "info", "warn" (or "warning") and "error", any case.

Types

type Attr

type Attr struct{ Key, Value string }

Attr is one attribute of a record, its value rendered as text and cut.

type Handler

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

Handler is a slog.Handler that records into a Ring and forwards to the handler it wraps.

func NewHandler

func NewHandler(next slog.Handler, ring *Ring, level *slog.LevelVar) *Handler

NewHandler wraps next. level decides what is recorded and forwarded; next must not filter by a stricter level of its own (build it with the same LevelVar).

func (*Handler) Enabled

func (h *Handler) Enabled(_ context.Context, l slog.Level) bool

Enabled implements slog.Handler.

func (*Handler) Handle

func (h *Handler) Handle(ctx context.Context, r slog.Record) error

Handle implements slog.Handler.

func (*Handler) WithAttrs

func (h *Handler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs implements slog.Handler.

func (*Handler) WithGroup

func (h *Handler) WithGroup(name string) slog.Handler

WithGroup implements slog.Handler.

type Record

type Record struct {
	Seq       int64 // 1, 2, 3 ...: grows with every record, never reused; the cursor of a read
	Time      time.Time
	Level     slog.Level
	Message   string
	Component string // attribute "component", else the word before the first ": " of the message ("health: prune" -> "health")
	Code      string // attribute "code"
	RequestID string // attribute "request_id", else the id of the request context
	Attrs     []Attr
}

Record is one logged record as the ring keeps it.

type Ring

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

Ring is a fixed-size buffer of the latest records.

func New

func New(w io.Writer, format string, level slog.Level, capacity int) (*slog.Logger, *Ring, *slog.LevelVar)

New builds the process logger: text or JSON ("json") records to w at a level the owner can change later, kept in a ring of capacity records. The level var starts at level.

func NewRing

func NewRing(capacity int) *Ring

NewRing returns a ring of capacity records (DefaultCapacity when capacity < 1).

func (*Ring) Cap

func (r *Ring) Cap() int

Cap is the capacity.

func (*Ring) Len

func (r *Ring) Len() int

Len is the number of records held.

func (*Ring) Snapshot

func (r *Ring) Snapshot(before int64, limit int, keep func(*Record) bool) []Record

Snapshot returns the held records, newest first, whose Seq is below before (0 = from the newest) and for which keep (nil = all) is true, at most limit of them (limit < 1 = all). The records are copies.

Jump to

Keyboard shortcuts

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