testlog

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT 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 testlog captures slog records in tests (the gatekeeper's stand-in for zaptest/observer).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Record

type Record struct {
	Level   slog.Level
	Message string
	Attrs   map[string]string
}

Record is one captured log record with its attributes flattened to strings.

type Recorder

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

Recorder is a slog.Handler that keeps every record.

func New

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

New returns a logger and the recorder behind it.

func (*Recorder) Contains

func (r *Recorder) Contains(s string) bool

Contains reports whether any record's message or attribute value contains s (for "never logs a secret" tests).

func (*Recorder) Enabled

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

Enabled implements slog.Handler: every level is kept.

func (*Recorder) Handle

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

Handle implements slog.Handler.

func (*Recorder) Records

func (r *Recorder) Records() []Record

Records returns a copy of everything logged so far.

func (*Recorder) WithAttrs

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

WithAttrs implements slog.Handler.

func (*Recorder) WithGroup

func (r *Recorder) WithGroup(name string) slog.Handler

WithGroup implements slog.Handler.

Jump to

Keyboard shortcuts

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