logging

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package logging provides the bracket log handler for llm-router plus the events handler that persists records at or above the configured level to the events database while rendering them to stderr.

Package logging provides the bracket log handler for llm-router: [LEVEL][dd.mm.yyyy h:m:s.ms][key: value] message.

Index

Constants

View Source
const EventsQueueSize = 4096

EventsQueueSize bounds pending event writes. Sends block when full so no event is dropped; producers wait for the writer.

View Source
const TimeFormat = "02.01.2006 15:04:05.000"

TimeFormat renders record timestamps as dd.mm.yyyy h:m:s.ms.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventsHandler added in v0.4.0

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

EventsHandler persists records at or above the level to the events database and renders them to stderr in bracket format. Records below the level are dropped: never persisted, never rendered.

func NewEventsHandler added in v0.4.0

func NewEventsHandler(writer io.Writer, level slog.Level, service *events.Service) *EventsHandler

NewEventsHandler builds an EventsHandler writing display lines to writer at level and persisting through service. It starts the writer goroutine.

func (*EventsHandler) Drain added in v0.4.0

func (h *EventsHandler) Drain(timeout time.Duration) bool

Drain waits until the pending queue empties or timeout elapses, reporting whether the queue drained. Shutdown calls it after the listeners stop so the final lines persist before the events file vacuums. The writer keeps running; Drain only observes.

func (*EventsHandler) Enabled added in v0.4.0

func (h *EventsHandler) Enabled(_ context.Context, level slog.Level) bool

Enabled reports whether the record meets the persistence threshold. slog filters before Handle, so records below the level never reach it.

func (*EventsHandler) Fatal added in v0.4.0

func (h *EventsHandler) Fatal(message string, attributes ...any)

Fatal persists a fatal event synchronously, renders it, then exits.

func (*EventsHandler) Handle added in v0.4.0

func (h *EventsHandler) Handle(_ context.Context, record slog.Record) error

Handle drops records below the level, then renders the display line and enqueues the record for persistence. The send blocks when the queue is full.

func (*EventsHandler) SetService added in v0.4.0

func (h *EventsHandler) SetService(service *events.Service)

SetService wires the persistence target after construction. Startup creates the handler before the events database opens; the server sets the service once it exists. Display never waits for this.

func (*EventsHandler) WithAttrs added in v0.4.0

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

WithAttrs returns a Handler with attributes appended, qualified by groups.

func (*EventsHandler) WithGroup added in v0.4.0

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

WithGroup returns a Handler scoping subsequent attributes under name.

type Handler

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

Handler formats records as bracket groups. Each attribute renders as its own [key: value] group in call order. Groups flatten with dot separators.

func NewHandler

func NewHandler(writer io.Writer, level slog.Level) *Handler

NewHandler builds a Handler writing to writer at level.

func (*Handler) Enabled

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

Enabled reports whether level passes the configured threshold.

func (*Handler) Handle

func (h *Handler) Handle(_ context.Context, record slog.Record) error

Handle renders one record in bracket format.

func (*Handler) WithAttrs

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

WithAttrs returns a Handler with attributes appended, qualified by groups.

func (*Handler) WithGroup

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

WithGroup returns a Handler scoping subsequent attributes under name.

Jump to

Keyboard shortcuts

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