logtest

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package logtest provides a minimal, stdlib-only slog capture handler for asserting on log output in tests. It exists so the transit test suite can verify middleware logging without depending on go-tool-base's pkg/logger.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNoop

func NewNoop() *slog.Logger

NewNoop returns a *slog.Logger that discards all output. Use it where a test needs a logger but does not assert on captured records.

Types

type Buffer

type Buffer struct {
	*slog.Logger
	// contains filtered or unexported fields
}

Buffer captures log records in memory. It embeds a *slog.Logger backed by a capturing handler, so callers pass buf.Logger wherever a *slog.Logger is expected and then assert on Entries().

func New

func New() *Buffer

New returns a Buffer that captures every record at any level. Loggers derived from it via With/WithGroup capture into the same buffer.

func (*Buffer) Contains

func (b *Buffer) Contains(substr string) bool

Contains reports whether any captured record's message contains substr.

func (*Buffer) Entries

func (b *Buffer) Entries() []Entry

Entries returns all captured records, in order.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the number of captured records.

type Entry

type Entry struct {
	Level   slog.Level
	Message string
	Keyvals []any
}

Entry is a single captured log record, flattened for assertion. Keyvals holds the record's attributes (including those accumulated via With) as alternating key/value pairs.

Jump to

Keyboard shortcuts

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