logging

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package logging provides structured logging utilities with context propagation and OpenTelemetry trace integration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Component

func Component(ctx context.Context, name string) *slog.Logger

Component returns a logger with component name preset. The logger is extracted from context and enriched with "component" attribute.

func DiscardLogger

func DiscardLogger() *slog.Logger

DiscardLogger returns a logger that discards all output. Useful for tests that don't need to verify log output.

func FromContext

func FromContext(ctx context.Context) *slog.Logger

FromContext extracts logger from context. Falls back to slog.Default() if no logger is present.

func ReconcileIDFromContext

func ReconcileIDFromContext(ctx context.Context) string

ReconcileIDFromContext extracts the reconcile ID from context. Returns empty string if not present.

func TestLogger

func TestLogger(tb testing.TB) (*slog.Logger, *bytes.Buffer)

TestLogger returns a logger that captures output for assertions. The returned buffer contains all log output in JSON format.

func WithLogger

func WithLogger(ctx context.Context, logger *slog.Logger) context.Context

WithLogger returns a new context with the given logger embedded.

func WithReconcileID

func WithReconcileID(ctx context.Context) context.Context

WithReconcileID adds a reconcile-scoped request ID to context and returns a new context with the logger enriched with this ID.

Types

type TraceHandler

type TraceHandler struct {
	slog.Handler
}

TraceHandler wraps slog.Handler to automatically inject OpenTelemetry trace context (trace_id, span_id) into log records.

func NewTraceHandler

func NewTraceHandler(h slog.Handler) *TraceHandler

NewTraceHandler creates a new TraceHandler wrapping the given handler.

func (*TraceHandler) Handle

func (h *TraceHandler) Handle(ctx context.Context, r slog.Record) error

Handle injects trace_id and span_id from OpenTelemetry context into the log record.

func (*TraceHandler) WithAttrs

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

WithAttrs returns a new TraceHandler with additional attributes.

func (*TraceHandler) WithGroup

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

WithGroup returns a new TraceHandler with a new group.

Jump to

Keyboard shortcuts

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