Documentation
¶
Overview ¶
Package testlog provides a log handler for unit tests.
Index ¶
- func Logger(t Testing, level slog.Level) log.Logger
- func LoggerWithHandlerMod(t Testing, level slog.Level, handlerMod func(slog.Handler) slog.Handler) log.Logger
- type CapturingHandler
- func (c *CapturingHandler) Clear()
- func (c *CapturingHandler) Enabled(context.Context, slog.Level) bool
- func (c *CapturingHandler) FindLog(filters ...LogFilter) *HelperRecord
- func (c *CapturingHandler) FindLogs(filters ...LogFilter) []*HelperRecord
- func (c *CapturingHandler) Handle(ctx context.Context, r slog.Record) error
- func (c *CapturingHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (c *CapturingHandler) WithGroup(name string) slog.Handler
- type HelperRecord
- type LogFilter
- type Testing
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CapturingHandler ¶
type CapturingHandler struct { Logs *[]*slog.Record // shared among derived CapturingHandlers // contains filtered or unexported fields }
CapturingHandler provides a log handler that captures all log records and optionally forwards them to a delegate. Note that it is not thread safe.
func CaptureLogger ¶ added in v1.4.0
func (*CapturingHandler) Clear ¶
func (c *CapturingHandler) Clear()
func (*CapturingHandler) FindLog ¶
func (c *CapturingHandler) FindLog(filters ...LogFilter) *HelperRecord
func (*CapturingHandler) FindLogs ¶ added in v1.4.0
func (c *CapturingHandler) FindLogs(filters ...LogFilter) []*HelperRecord
type HelperRecord ¶
func (HelperRecord) AttrValue ¶ added in v1.4.0
func (h HelperRecord) AttrValue(name string) (v any)
type LogFilter ¶ added in v1.4.0
func NewAttributesContainsFilter ¶ added in v1.4.0
func NewAttributesFilter ¶ added in v1.4.0
func NewLevelFilter ¶ added in v1.4.0
func NewMessageContainsFilter ¶ added in v1.4.0
func NewMessageFilter ¶ added in v1.4.0
Click to show internal directories.
Click to hide internal directories.