util

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2025 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Err

func Err(err error) slog.Attr

Err creates a slog.Attr for an error Returns an empty Attr if err is nil, otherwise creates an Attr with key "error" and the error message as value

func ErrorCtx

func ErrorCtx(ctx context.Context, err error) context.Context

ErrorCtx extracts logging context from an error (if it was wrapped with WrapCtx) and adds it to the provided context

func ExtractLogAttrs

func ExtractLogAttrs(ctx context.Context) []slog.Attr

ExtractLogAttrs extracts all logging attributes from a context Returns the attributes as a slice of slog.Attr that can be added to a log record

func KV

func KV(key string, value any) slog.Attr

KV creates a slog.Attr with the given key and value This is a convenience wrapper around slog.Any

func NewMockLogger

func NewMockLogger() *slog.Logger

func UpdateLogCtx

func UpdateLogCtx(ctx context.Context, key string, value any) context.Context

UpdateLogCtx adds a key-value pair to the context for logging This function can be used to add structured data that will be included in all subsequent log entries using this context

func WrapCtx

func WrapCtx(ctx context.Context, err error) error

WrapCtx wraps an error with the logging context from the provided context This allows context information to propagate along with errors

Types

type MockHandler

type MockHandler struct{} //nolint:revive, gocritic

func (*MockHandler) Enabled

func (m *MockHandler) Enabled(_ context.Context, _ slog.Level) bool

func (*MockHandler) Handle

func (m *MockHandler) Handle(_ context.Context, _ slog.Record) error

func (*MockHandler) WithAttrs

func (m *MockHandler) WithAttrs(_ []slog.Attr) slog.Handler

func (*MockHandler) WithGroup

func (m *MockHandler) WithGroup(_ string) slog.Handler

Jump to

Keyboard shortcuts

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