Help us shape the future of Go! Take the 2026 Go Developer Survey

logtest

package
v2.68.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogRecorder

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

LogRecorder - a struct that implements the slog.Handler interface and captures all emitted log lines under a Records field.

func NewWithRecorder

func NewWithRecorder(cfg *log.Config) (*slog.Logger, *LogRecorder)

NewWithRecorder - a helper constructor that returns an slog Logger that uses the LogRecorder handler. This enables engineers to configure their tests with a standard slogger, and then perform assertions that their code is instrumented properly.

func (*LogRecorder) Attrs

func (h *LogRecorder) Attrs() []slog.Attr

Attrs returns a copy of the handler's attributes (thread-safe).

func (*LogRecorder) Enabled

func (h *LogRecorder) Enabled(context.Context, slog.Level) bool

Enabled - this handler should always be enabled. Warning - this is a test-only handler.

func (*LogRecorder) Handle

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

Handle - allows us to capture slog.Record's emitted to the log. This enables us to assert that logs are correctly emitted from user-space code.

func (*LogRecorder) Records

func (h *LogRecorder) Records() []testRecord

Records returns a copy of all recorded log records (thread-safe).

func (*LogRecorder) WithAttrs

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

WithAttrs - a method that is necessary to satisfy the slog.Handler interface.

Warning - this is a test-only handler.

func (*LogRecorder) WithGroup

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

WithGroup - a method that is necessary to satisfy the slog.Handler interface.

Warning - this is a test-only handler.

Jump to

Keyboard shortcuts

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