testlogger

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package testlogger provides a slog handler which can handle t.Parallel() tests while being a global logging handler, redirecting it to the correct underlying logger for each test thread.

This package also muffles certain log messages to reduce noise in the snapshots and to keep the snapshots consistent across runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

Handler can be set as the global logging handler before the test starts, and individual test cases can add their own instance/implementation of the cmdlogger.CmdLogger interface.

func New

func New() *Handler

func (*Handler) AddInstance

func (tl *Handler) AddInstance(logger cmdlogger.CmdLogger)

AddInstance adds a "global" logger to this specific test run.

func (*Handler) Delete

func (tl *Handler) Delete()

Delete removes the logger created by AddInstance() This **must** be called before a test ends, as the same memory address may be reused.

func (*Handler) Enabled

func (tl *Handler) Enabled(ctx context.Context, level slog.Level) bool

func (*Handler) Handle

func (tl *Handler) Handle(ctx context.Context, record slog.Record) error

func (*Handler) HasErrored

func (tl *Handler) HasErrored() bool

HasErrored returns true if there have been any calls to Handle with a level of slog.LevelError

func (*Handler) SendEverythingToStderr

func (tl *Handler) SendEverythingToStderr()

SendEverythingToStderr tells the logger to send all logs to stderr regardless of their level.

This is useful if we're expecting to output structured data to stdout such as JSON, which cannot be mixed with other output.

func (*Handler) SetLevel

func (tl *Handler) SetLevel(level slog.Leveler)

func (*Handler) WithAttrs

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

func (*Handler) WithGroup

func (tl *Handler) WithGroup(g string) slog.Handler

Jump to

Keyboard shortcuts

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