Documentation
¶
Overview ¶
Package slogstub provides test stubs for the log/slog package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FuncHandler ¶
type FuncHandler struct {
// EnabledFunc determines if the handler is enabled for the given level.
EnabledFunc func(ctx context.Context, level slog.Level) bool
// HandleFunc processes a log record.
HandleFunc func(ctx context.Context, record slog.Record) error
// WithAttrsFunc returns a new handler with additional attributes.
WithAttrsFunc func(attrs []slog.Attr) slog.Handler
// WithGroupFunc returns a new handler with a group name.
WithGroupFunc func(name string) slog.Handler
}
FuncHandler implements slog.Handler using configurable functions.
This type is useful for testing code that emits structured log events, allowing tests to capture and inspect slog.Record values directly rather than parsing serialized output.
Each function field must be set before calling the corresponding method. Calling a method when its function field is nil will panic.
func (*FuncHandler) Enabled ¶
Enabled implements slog.Handler.
func (*FuncHandler) Handle ¶
Handle implements slog.Handler.
func (*FuncHandler) WithAttrs ¶
func (h *FuncHandler) WithAttrs(attrs []slog.Attr) slog.Handler
WithAttrs implements slog.Handler.
func (*FuncHandler) WithGroup ¶
func (h *FuncHandler) WithGroup(name string) slog.Handler
WithGroup implements slog.Handler.
Click to show internal directories.
Click to hide internal directories.