logstream

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package logstream captures the application's own slog output into a bounded in-memory ring buffer and fans it out to live subscribers. It backs the diagnostics endpoints' "recent logs" backlog and the live backend-log WebSocket stream. It deliberately depends only on the shared types package so both bootstrap (which installs the slog handler) and the API handlers (which read it) can use it without an import cycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSlogHandler

func NewSlogHandler(base slog.Handler, b *Broadcaster) slog.Handler

NewSlogHandler returns a slog.Handler that tees records to base and to b.

Types

type Broadcaster

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

Broadcaster keeps a bounded ring buffer of recent log entries and fans new entries out to any active subscribers. It is safe for concurrent use.

func Default

func Default() *Broadcaster

Default returns the package-level Broadcaster singleton.

func New

func New(capacity int) *Broadcaster

New returns a Broadcaster retaining up to capacity recent entries.

func (*Broadcaster) Append

func (b *Broadcaster) Append(e Entry)

Append records an entry in the ring buffer and delivers it to subscribers. Delivery is non-blocking; a subscriber whose buffer is full drops the entry.

func (*Broadcaster) Recent

func (b *Broadcaster) Recent() []Entry

Recent returns the buffered entries in chronological order (oldest first).

func (*Broadcaster) Subscribe

func (b *Broadcaster) Subscribe() (<-chan Entry, func())

Subscribe registers a new live subscriber. It returns a receive-only channel of subsequent entries and a cancel func that unsubscribes and closes the channel. cancel is idempotent.

type Entry

type Entry = system.LogEntry

Entry is a single captured log record.

Jump to

Keyboard shortcuts

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