Help us shape the future of Go! Take the 2026 Go Developer Survey

logtest

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package logtest redirects the process-wide logger output for the length of a test, so a test can assert what was logged or keep expected errors out of the test output. The logger output is global: tests using it must not run in parallel with other tests that log.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Discard

func Discard(t *testing.T)

Discard drops every log entry until t ends, then restores the previous output.

Types

type Buffer

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

Buffer holds the log entries written while it is installed.

func NewCollector

func NewCollector(t *testing.T) *Buffer

NewCollector collects every log entry until t ends, then restores the previous output.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset drops the entries collected so far.

func (*Buffer) String

func (b *Buffer) String() string

String returns the entries collected so far, one per line.

Jump to

Keyboard shortcuts

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