Standard library / log/slog

slog.Handler

Contract for filtering, processing and deriving handlers. Implementations must handle concurrent calls safely. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
type Handler interface {  Enabled(context.Context, Level) bool
  Handle(context.Context, Record) error
  WithAttrs(attrs []Attr) Handler
  WithGroup(name string) Handler}

Working Example

Example Snippetgo
package main
import (  "context"  "fmt"  "io"  "log/slog")
func main() {  var h slog.Handler = slog.NewTextHandler(io.Discard, nil)  fmt.Println(h.Enabled(context.Background(), slog.LevelInfo))}
Go Reference