slogtest

package
v0.0.0-...-8f64456 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Honestly, got ChatGPT to give me this. Looks reasonable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogEntry

type LogEntry struct {
	Level   slog.Level
	Message string
	Attrs   map[string]any
}

LogEntry represents a single captured log record.

type MockHandler

type MockHandler struct {
	// contains filtered or unexported fields
}

MockHandler implements slog.Handler and stores logs in memory.

func NewLogger

func NewLogger() (*slog.Logger, *MockHandler)

func NewMockHandler

func NewMockHandler(level slog.Level) *MockHandler

NewMockHandler creates a new MockHandler.

func (*MockHandler) Clear

func (h *MockHandler) Clear()

Clear removes all stored log entries (useful between tests).

func (*MockHandler) Enabled

func (h *MockHandler) Enabled(_ context.Context, level slog.Level) bool

Enabled implements slog.Handler.Enabled.

func (*MockHandler) Handle

func (h *MockHandler) Handle(_ context.Context, record slog.Record) error

Handle implements slog.Handler.Handle.

func (*MockHandler) Logs

func (h *MockHandler) Logs() []LogEntry

Logs returns a snapshot of all log entries.

func (*MockHandler) MustHaveSeen

func (h *MockHandler) MustHaveSeen(t *testing.T, msg string, level slog.Level, attrs map[string]any)

func (*MockHandler) WithAttrs

func (h *MockHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs implements slog.Handler.WithAttrs.

func (*MockHandler) WithGroup

func (h *MockHandler) WithGroup(_ string) slog.Handler

WithGroup implements slog.Handler.WithGroup.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL