Documentation
¶
Index ¶
Constants ¶
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 DumpRingBuffer ¶
DumpRingBuffer writes the ring buffer contents to a file.
func ForComponent ¶
ForComponent returns a sub-logger with the component field set. Uses a dynamicHandler so that loggers created before Init() (e.g., as package-level vars) will correctly use the real handler once Init() runs.
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.
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.
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.