logtest

package
v0.77.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package logtest captures slog output in tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logs

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

Logs records slog output for assertions.

func Capture

func Capture(t *testing.T) *Logs

Capture swaps slog's global default for a recorder until the test ends. Tests using it must not call t.Parallel, since the default is process-wide.

func (*Logs) AttrsFor

func (c *Logs) AttrsFor(level slog.Level, msg string) []map[string]any

AttrsFor returns the attributes of every captured record of the given level and message.

func (*Logs) Enabled

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

Enabled reports that every level is recorded.

func (*Logs) Handle

func (c *Logs) Handle(_ context.Context, r slog.Record) error

Handle records r.

func (*Logs) LogCount

func (c *Logs) LogCount(level slog.Level, msg string) int

LogCount returns how many records of the given level and message were captured.

func (*Logs) RecordsAt

func (c *Logs) RecordsAt(level slog.Level) []map[string]any

RecordsAt returns the attributes of every record at the given level.

func (*Logs) WarnsFor

func (c *Logs) WarnsFor(clientID string) []map[string]any

WarnsFor returns the attributes of every WARN record keyed on clientID.

func (*Logs) WithAttrs

func (c *Logs) WithAttrs([]slog.Attr) slog.Handler

WithAttrs returns c unchanged.

func (*Logs) WithGroup

func (c *Logs) WithGroup(string) slog.Handler

WithGroup returns c unchanged.

Jump to

Keyboard shortcuts

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