capture

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: GPL-2.0, GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package capture is an auth-internal test helper: a slog.Handler that records log records so tests can assert on auth's logging decisions, plus a helper to install it as the default logger.

It is deliberately auth-internal rather than a dependency on an external logging helper (e.g. slogx/capture): auth is a foundational library, and a ~50-line, never-changing test handler is not worth a new module edge. Import it only from auth's _test.go files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Recorder

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

Recorder is a slog.Handler that captures every record regardless of level so tests can assert on what was logged. It is safe for concurrent use.

func Default

func Default(tb testing.TB) *Recorder

Default installs a fresh Recorder as slog's default logger and restores the previous default via tb.Cleanup. Use it for code that logs through slog.Default(); because it mutates global state the test must not run in parallel.

func New

func New() (*slog.Logger, *Recorder)

New returns a Recorder and an *slog.Logger writing to it, for code that takes an injected logger. It does not touch the global default, so a test using it may run in parallel.

func (*Recorder) CountMsg

func (rec *Recorder) CountMsg(sub string) int

CountMsg returns how many captured records have a message containing sub.

func (*Recorder) Enabled

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

Enabled reports true for every level so nothing is filtered before capture.

func (*Recorder) Handle

func (rec *Recorder) Handle(_ context.Context, r slog.Record) error

Handle records a clone of r. It satisfies slog.Handler.

func (*Recorder) WithAttrs

func (rec *Recorder) WithAttrs([]slog.Attr) slog.Handler

WithAttrs returns the Recorder unchanged; base attributes are not captured.

func (*Recorder) WithGroup

func (rec *Recorder) WithGroup(string) slog.Handler

WithGroup returns the Recorder unchanged; groups are not captured.

Jump to

Keyboard shortcuts

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