slogtest

package
v0.0.0-...-c530b97 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: ISC Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Capture

type Capture[T any] struct {
	// contains filtered or unexported fields
}

Capture is an io.Writer that unmarshals the written data into entries of type T, to be later retrieved with Entries(). Written buffers must be valid JSON by themselves, and if the unmarshaling errors, Write will return an error.

func (*Capture[T]) Entries

func (c *Capture[T]) Entries() []T

Entries returns the captured entries.

func (*Capture[T]) Write

func (c *Capture[T]) Write(data []byte) (n int, err error)

Write implements io.Writer.

type ErrorHandler

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

ErrorHandler is used for capturing errors from a slog.Handler as slog.Logger swallows them.

func NewErrorHandler

func NewErrorHandler(inner slog.Handler) *ErrorHandler

NewErrorHandler returns a new ErrorHandler.

func NewWithErrorHandler

func NewWithErrorHandler(h slog.Handler) (*slog.Logger, *ErrorHandler)

NewWithErrorHandler wraps the passed slog.Handler into an ErrorHandler, creates a new slog.Logger, then returns the Logger and the ErrorHandler.

func (*ErrorHandler) Enabled

func (h *ErrorHandler) Enabled(ctx context.Context, level slog.Level) bool

Enabled implements slog.Handler.

func (*ErrorHandler) Err

func (h *ErrorHandler) Err() error

Err returns the captured error(s).

func (*ErrorHandler) Handle

func (h *ErrorHandler) Handle(ctx context.Context, r slog.Record) error

Handle implements slog.Handler.

func (*ErrorHandler) WithAttrs

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

WithAttrs implements slog.Handler.

func (*ErrorHandler) WithGroup

func (h *ErrorHandler) WithGroup(name string) slog.Handler

WithGroup implements slog.Handler.

Jump to

Keyboard shortcuts

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