logtest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package logtest points slog's default logger somewhere a test can use. The packages log through slog.Default() rather than an injected logger, so a test reaches their output by swapping the default. It imports nothing from the repository, so every package's tests can use it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Silence

func Silence()

Silence discards everything logged through the default logger. Call it from a package's TestMain so a failing test's output is not buried in log lines.

Types

type Buffer

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

Buffer is a concurrency-safe log sink: the code under test may log from its own goroutines while the test reads.

func Capture

func Capture(t testing.TB, level slog.Level) *Buffer

Capture routes the default logger to the returned Buffer as JSON records at level and above, until the test ends. The default logger is process-wide, so a test that captures must not call t.Parallel: serial tests never overlap the package's parallel ones, which is what keeps another test's lines out of the buffer.

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes returns a copy of what has been logged so far.

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