Documentation
¶
Overview ¶
Package logrec provides a slog.Handler implementation for recording logs during tests.
Usage:
var rec *logrec.Recorder
func TestMain(m *testing.M) {
rec = logrec.New()
slog.SetDefault(slog.New(rec.Handler()))
os.Exit(m.Run())
}
func TestSomething(t *testing.T) {
tid := testid.New(t)
ctx := testid.WithValue(t.Context(), tid)
rec.Start(t, ctx)
slog.InfoContext(ctx, "message", "key", "value")
for record := range rec.Result(ctx).All() {
// inspect record
}
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder manages log records per test ID (tid). It allows parallel tests to record their logs independently. Use New to create a Recorder, Recorder.Handler to get a slog.Handler, Recorder.Start to begin recording, and Recorder.Result to retrieve the recorded logs.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result holds the recorded log entries for a specific test ID. Use Result.All to iterate over the recorded logs.
Click to show internal directories.
Click to hide internal directories.