Documentation
¶
Overview ¶
Package handlers provides simple slog handlers
Index ¶
- func NewDisabled() slog.Handler
- func NewFormat(formatter func(ctx context.Context, r slog.Record) string, writer io.Writer) slog.Handler
- func NewLevel(lvl slog.Leveler, innerHandler slog.Handler) slog.Handler
- func NewLocking(inner slog.Handler) slog.Handler
- func NewMulti(handlers ...slog.Handler) slog.Handler
- type Async
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDisabled ¶
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 NewLocking ¶
NewLocking returns a new locking handler that wraps the given inner handler. Only the Handle method is synchronized, Enabled is not.
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 ¶
NewAsync creates a new Async handler.
The Async must be closed to avoid leaks.
When using WithAttrs or WithGroup, a single goroutine and queue is still used to write the messages, to guarantee that the log messages are still handled in correct order and the inner handler is not called concurrently. It also avoids leaks by ensuring we don't have to close handlers returned by WithAttrs or WithGroup. For performance, we could have a different goroutine and queue for each derived handler.
func (*Async) Flush ¶
func (h *Async) Flush()
Flush writes all messages in the queue to the inner handler.