Documentation
¶
Index ¶
- type LogRecorder
- func (h *LogRecorder) Attrs() []slog.Attr
- func (h *LogRecorder) Enabled(context.Context, slog.Level) bool
- func (h *LogRecorder) Handle(ctx context.Context, r slog.Record) error
- func (h *LogRecorder) Records() []testRecord
- func (h *LogRecorder) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *LogRecorder) WithGroup(name string) slog.Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LogRecorder ¶
type LogRecorder struct {
// contains filtered or unexported fields
}
LogRecorder - a struct that implements the slog.Handler interface and captures all emitted log lines under a Records field.
func NewWithRecorder ¶
func NewWithRecorder() (*slog.Logger, *LogRecorder)
NewWithRecorder - a helper constructor that returns an slog Logger that uses the LogRecorder handler. This enables engineers to configure their tests with a standard slogger, and then perform assertions that their code is instrumented properly.
func (*LogRecorder) Attrs ¶
func (h *LogRecorder) Attrs() []slog.Attr
Attrs returns a copy of the handler's attributes (thread-safe).
func (*LogRecorder) Enabled ¶
Enabled - this handler should always be enabled. Warning - this is a test-only handler.
func (*LogRecorder) Handle ¶
Handle - allows us to capture slog.Record's emitted to the log. This enables us to assert that logs are correctly emitted from user-space code.
func (*LogRecorder) Records ¶
func (h *LogRecorder) Records() []testRecord
Records returns a copy of all recorded log records (thread-safe).