Documentation ¶
Overview ¶
Package slogtest provides utilities for emitting test logs using clog.
func TestExample(t *testing.T) { ctx := slogtest.Context(t) clog.FromContext(ctx).With("foo", "bar").Info("hello world") }
This produces the following test output:
=== RUN TestExample slogtest.go:24: level=INFO source=/path/to/example_test.go:13 msg="hello world" foo=bar
This package is intended to be used in tests only.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RemoveTime ¶
RemoveTime removes the top-level time attribute. It is intended to be used as a ReplaceAttr function, to make example output deterministic.
This is taken from slog/internal/slogtest.RemoveTime.
func TestContextWithLogger
deprecated
func TestLogger ¶
TestLogger gets a logger to use in unit and end to end tests. This logger is configured to log at debug level.
func TestLoggerWithOptions ¶ added in v1.5.0
func TestLoggerWithOptions(t Logger, opts *slog.HandlerOptions) *clog.Logger
TestLoggerWithOptions gets a logger to use in unit and end to end tests.
Types ¶
Click to show internal directories.
Click to hide internal directories.