github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/kit/logr/slog/handler.go (about)

     1  package slog
     2  
     3  import (
     4  	"context"
     5  	"log/slog"
     6  )
     7  
     8  func Default() *slog.Logger {
     9  	return slog.New(&handler{h: slog.Default().Handler()})
    10  }
    11  
    12  type handler struct {
    13  	h slog.Handler
    14  }
    15  
    16  func (h *handler) Handle(ctx context.Context, r slog.Record) error {
    17  	return h.h.Handle(ctx, r)
    18  }
    19  
    20  func (h *handler) WithAttrs(attrs []slog.Attr) slog.Handler {
    21  	return &handler{h: h.h.WithAttrs(attrs)}
    22  }
    23  
    24  func (h *handler) WithGroup(name string) slog.Handler {
    25  	return &handler{h: h.h.WithGroup(name)}
    26  }
    27  
    28  func (h *handler) Enabled(_ context.Context, l slog.Level) bool {
    29  	return l >= slog.LevelDebug
    30  }