logging

package
v0.10.19 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CompStatus  = "status"
	CompMCP     = "mcp"
	CompNotif   = "notif"
	CompPerf    = "perf"
	CompUI      = "ui"
	CompSession = "session"
	CompStorage = "storage"
	CompPool    = "pool"
	CompHTTP    = "http"
)

Component constants for structured logging.

Variables

This section is empty.

Functions

func Aggregate

func Aggregate(component, key string, fields ...slog.Attr)

Aggregate records a high-frequency event for batched logging.

func DumpRingBuffer

func DumpRingBuffer(path string) error

DumpRingBuffer writes the ring buffer contents to a file.

func ForComponent

func ForComponent(name string) *slog.Logger

ForComponent returns a sub-logger with the component field set.

func Init

func Init(cfg Config)

Init initializes the global logging system. When debug is false and no log dir is provided, logs are discarded.

func Logger

func Logger() *slog.Logger

Logger returns the global logger. Safe to call before Init (returns default).

func Shutdown

func Shutdown()

Shutdown flushes the aggregator and closes writers.

Types

type Aggregator

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

Aggregator batches high-frequency events and emits summaries periodically.

func NewAggregator

func NewAggregator(logger *slog.Logger, intervalSecs int) *Aggregator

NewAggregator creates an aggregator that flushes every intervalSecs seconds. If logger is nil, recorded events are silently dropped.

func (*Aggregator) Record

func (a *Aggregator) Record(component, event string, fields ...slog.Attr)

Record increments the counter for an event type. fields are kept from the most recent call (last-writer-wins for context).

func (*Aggregator) Start

func (a *Aggregator) Start()

Start begins the background flush goroutine.

func (*Aggregator) Stop

func (a *Aggregator) Stop()

Stop flushes remaining entries and stops the background goroutine.

type BridgeWriter

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

BridgeWriter wraps slog as an io.Writer so that legacy log.Printf calls flow through the structured logging system. It parses the common "[CATEGORY] message" prefix pattern used throughout agent-deck and extracts the category into a structured "component" field.

func NewBridgeWriter

func NewBridgeWriter(defaultComponent string) *BridgeWriter

NewBridgeWriter creates a writer that forwards writes to slog. The defaultComponent is used when no [CATEGORY] prefix is found.

func (*BridgeWriter) Write

func (bw *BridgeWriter) Write(p []byte) (int, error)

Write implements io.Writer. Each write is treated as one log line. It strips the standard log timestamp prefix (if present from log.SetFlags) and parses [CATEGORY] prefixes into structured fields.

type Config

type Config struct {
	// LogDir is the directory for log files (e.g. ~/.agent-deck)
	LogDir string

	// Level is the minimum log level: "debug", "info", "warn", "error"
	Level string

	// Format is "json" (default) or "text"
	Format string

	// MaxSizeMB is the max size in MB before rotation (default: 10)
	MaxSizeMB int

	// MaxBackups is rotated files to keep (default: 5)
	MaxBackups int

	// MaxAgeDays is days to keep rotated files (default: 10)
	MaxAgeDays int

	// Compress rotated files (default: true)
	Compress bool

	// RingBufferSize is the in-memory ring buffer size in bytes (default: 10MB)
	RingBufferSize int

	// AggregateIntervalSecs is the aggregation flush interval (default: 30)
	AggregateIntervalSecs int

	// PprofEnabled starts pprof server on localhost:6060
	PprofEnabled bool

	// Debug indicates whether debug mode is active
	Debug bool
}

Config holds logging configuration.

type RingBuffer

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

RingBuffer is a thread-safe circular byte buffer. It implements io.Writer and silently overwrites old data when full.

func NewRingBuffer

func NewRingBuffer(size int) *RingBuffer

NewRingBuffer creates a ring buffer with the given capacity in bytes.

func (*RingBuffer) Bytes

func (rb *RingBuffer) Bytes() []byte

Bytes returns the buffer contents in chronological order.

func (*RingBuffer) DumpToFile

func (rb *RingBuffer) DumpToFile(path string) error

DumpToFile writes the ring buffer contents to a file in chronological order.

func (*RingBuffer) Write

func (rb *RingBuffer) Write(p []byte) (int, error)

Write implements io.Writer. Data wraps around when the buffer is full.

Jump to

Keyboard shortcuts

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