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 CapturedAttributes
- type CapturedRecord
- type CapturingHandler
- func (c *CapturingHandler) Clear()
- func (c *CapturingHandler) Enabled(context.Context, slog.Level) bool
- func (c *CapturingHandler) FindLog(filters ...LogFilter) *CapturedRecord
- func (c *CapturingHandler) FindLogs(filters ...LogFilter) []*CapturedRecord
- 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 LogFilter
- type Testing
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CapturedAttributes ¶ added in v1.9.1
type CapturedAttributes struct { Parent *CapturedAttributes Attributes []slog.Attr }
CapturedAttributes forms a chain of inherited attributes, to traverse on captured log records.
func (*CapturedAttributes) Attrs ¶ added in v1.9.1
func (r *CapturedAttributes) Attrs(f func(slog.Attr) bool)
Attrs calls f on each Attr in the CapturedAttributes. Iteration stops if f returns false.
type CapturedRecord ¶ added in v1.9.1
type CapturedRecord struct { Parent *CapturedAttributes *slog.Record }
CapturedRecord is a wrapped around a regular log-record, to preserve the inherited attributes context, without mutating the record or reordering attributes.
func (*CapturedRecord) AttrValue ¶ added in v1.9.1
func (h *CapturedRecord) AttrValue(name string) (v any)
func (*CapturedRecord) Attrs ¶ added in v1.9.1
func (r *CapturedRecord) Attrs(f func(slog.Attr) bool)
Attrs calls f on each Attr in the CapturedRecord. Iteration stops if f returns false.
type CapturingHandler ¶
type CapturingHandler struct { Logs *[]*CapturedRecord // 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.5.1
func (*CapturingHandler) Clear ¶
func (c *CapturingHandler) Clear()
func (*CapturingHandler) FindLog ¶
func (c *CapturingHandler) FindLog(filters ...LogFilter) *CapturedRecord
func (*CapturingHandler) FindLogs ¶ added in v1.6.1
func (c *CapturingHandler) FindLogs(filters ...LogFilter) []*CapturedRecord
type LogFilter ¶ added in v1.6.1
type LogFilter func(record *CapturedRecord) bool
func NewAttributesContainsFilter ¶ added in v1.7.2
func NewAttributesFilter ¶ added in v1.7.2
func NewLevelFilter ¶ added in v1.6.1
func NewMessageContainsFilter ¶ added in v1.6.1
func NewMessageFilter ¶ added in v1.6.1
Click to show internal directories.
Click to hide internal directories.