slogtest

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: MIT Imports: 9 Imported by: 17

Documentation

Overview

Package slogtest contains the slogger for use with Go's testing package.

If imported, then all logs that go through the stdlib's default logger will go through slog.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(t testing.TB, msg string, fields ...any)

Debug logs the given msg and fields to t via t.Log at the debug level.

func Error

func Error(t testing.TB, msg string, fields ...any)

Error logs the given msg and fields to t via t.Error at the error level.

func Fatal

func Fatal(t testing.TB, msg string, fields ...any)

Fatal logs the given msg and fields to t via t.Fatal at the fatal level.

func Info

func Info(t testing.TB, msg string, fields ...any)

Info logs the given msg and fields to t via t.Log at the info level.

func Make

func Make(tb testing.TB, opts *Options) slog.Logger

Make creates a Logger that writes logs to tb in a human readable format.

Types

type Options

type Options struct {
	// IgnoreErrors causes the test logger to not fatal the test
	// on Fatal and not error the test on Error or Critical.
	IgnoreErrors bool
	// SkipCleanup skips adding a t.Cleanup call that prevents the logger from
	// logging after a test has exited. This is necessary because race
	// conditions exist when t.Log is called concurrently of a test exiting. Set
	// to true if you don't need this behavior.
	SkipCleanup bool
}

Options represents the options for the logger returned by Make.

Directories

Path Synopsis
Package assert is a helper package for test assertions.
Package assert is a helper package for test assertions.

Jump to

Keyboard shortcuts

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