trace

package
v0.0.0-...-99f10aa Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithAttrs

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

WithAttrs returns a context with the given attributes attached. Any LogHandler that handles a record with this context will include these attributes in the record.

Types

type LogHandler

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

LogHandler is an slog.Handler that forwards records to an inner handler and buffers them so they can be dumped as a table via LogHandler.Dump. All copies produced by slog.Handler.WithAttrs and slog.Handler.WithGroup share the same buffer, so [Dump] can be called on any copy.

func NewLogHandler

func NewLogHandler(inner slog.Handler, level slog.Level) *LogHandler

func (*LogHandler) Dump

func (h *LogHandler) Dump(w io.Writer)

Dump writes the buffered records as a tab-aligned table to w. Columns are LEVEL, MSG, and one column per unique attribute key in order of first appearance.

func (*LogHandler) DumpString

func (h *LogHandler) DumpString() string

DumpString is a convenience wrapper around [Dump] that returns the table as a string.

func (*LogHandler) Enabled

func (h *LogHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*LogHandler) Handle

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

func (*LogHandler) WithAttrs

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

func (*LogHandler) WithGroup

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

Jump to

Keyboard shortcuts

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