handlers

package
v0.75.2 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package handlers provides simple slog handlers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDisabled

func NewDisabled() slog.Handler

NewDisabled returns a handler which never writes anything.

func NewFormat

func NewFormat(formatter func(ctx context.Context, r slog.Record) string, writer io.Writer) slog.Handler

NewFormat returns a handler that formats records and writes them to an io.Writer.

func NewLevel

func NewLevel(lvl slog.Leveler, innerHandler slog.Handler) slog.Handler

NewLevel returns a handler that filters logs based on a level.

func NewLocking

func NewLocking(inner slog.Handler) slog.Handler

NewLocking returns a new locking handler that wraps the given inner handler. Only the Handle method is synchronized, Enabled is not.

func NewMulti

func NewMulti(handlers ...slog.Handler) slog.Handler

NewMulti creates a new Handler that writes to multiple handlers.

Types

type Async

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

Async is a slog handler that asynchronously writes logs to another slog handler.

func NewAsync

func NewAsync(innerHandler slog.Handler) *Async

NewAsync creates a new Async handler.

The Async must be closed to avoid leaks.

func (*Async) Close

func (h *Async) Close()

Close closes the handler.

func (*Async) Enabled

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

Enabled returns true if the handler is enabled for the given level.

func (*Async) Flush

func (h *Async) Flush()

Flush writes all messages in the queue to the inner handler.

func (*Async) Handle

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

Handle writes a record to the handler.

func (*Async) WithAttrs

func (h *Async) WithAttrs(_attrs []slog.Attr) slog.Handler

WithAttrs returns a new handler with the given attributes.

func (*Async) WithGroup

func (h *Async) WithGroup(_name string) slog.Handler

WithGroup returns a new handler with the given group name.

Jump to

Keyboard shortcuts

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