logging

package
v1.0.5 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const LogAttrsKey ctxKey = "log_attrs"

LogAttrsKey is the context key for storing log attributes.

Variables

This section is empty.

Functions

func WithAttrs

func WithAttrs(ctx context.Context, attrs ...slog.Attr) context.Context

WithAttrs adds attributes to the context for automatic inclusion in logs.

Types

type ContextHandler

type ContextHandler struct {
	slog.Handler
}

ContextHandler is a slog.Handler that extracts attributes from context.

func NewContextHandler

func NewContextHandler(h slog.Handler) *ContextHandler

NewContextHandler creates a new ContextHandler wrapping the given handler.

func (*ContextHandler) Handle

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

Handle extracts attributes from context and adds them to the log record.

func (*ContextHandler) WithAttrs

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

WithAttrsHandler returns a new ContextHandler with the given attributes.

func (*ContextHandler) WithGroup

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

WithGroup returns a new ContextHandler with the given group.

Jump to

Keyboard shortcuts

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