testlog

package
v0.1.29 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package testlog provides the shared slog-capture helper for pkg/ unit tests that assert on global-logger output (the engine's warn paths log via the process-wide slog default; see the D32 note in CLAUDE.md). Living under pkg/internal it is importable by every pkg/... test file while remaining invisible to external embedders.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

Buffer is a goroutine-safe writer for capturing log output.

func Capture

func Capture(t *testing.T) *Buffer

Capture swaps the default slog logger for the test's duration and returns the buffer collecting its output. Tests using it must not run in parallel — the default logger is process-global state.

The captured logger runs at the handler's DEFAULT level (Info), so a Debug record is dropped. That is deliberate: a test asserting that something is logged at Debug rather than Warn wants both halves of the claim, and CaptureLevel(t, slog.LevelDebug) supplies the level-aware form.

func CaptureLevel added in v0.1.22

func CaptureLevel(t *testing.T, level slog.Level) *Buffer

CaptureLevel is Capture with an explicit minimum level, so a test can assert on records the default Info threshold would drop. Pass slog.LevelDebug to see Debug records; the captured text still carries each record's own level, so a test can distinguish "logged at Debug" from "logged at Warn" rather than merely "logged".

func (*Buffer) String

func (b *Buffer) String() string

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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