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
- type EventsHandler
- func (h *EventsHandler) Drain(timeout time.Duration) bool
- func (h *EventsHandler) Enabled(_ context.Context, level slog.Level) bool
- func (h *EventsHandler) Fatal(message string, attributes ...any)
- func (h *EventsHandler) Handle(_ context.Context, record slog.Record) error
- func (h *EventsHandler) SetService(service *events.Service)
- func (h *EventsHandler) WithAttrs(attributes []slog.Attr) slog.Handler
- func (h *EventsHandler) WithGroup(name string) slog.Handler
- type Handler
Constants ¶
const EventsQueueSize = 4096
EventsQueueSize bounds pending event writes. Sends block when full so no event is dropped; producers wait for the writer.
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
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
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
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.
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 ¶
NewHandler builds a Handler writing to writer at level.