// Package obs sets up logging and metrics in one place. package obs import ( "log/slog" "os" "strings" ) // Options controls logger setup. type Options struct { Level string // debug, info, warn, error Format string // text, json } // Setup installs the default slog logger and returns it. func Setup(o Options) *slog.Logger { var lvl slog.Level switch strings.ToLower(o.Level) { case "debug": lvl = slog.LevelDebug case "warn": lvl = slog.LevelWarn case "error": lvl = slog.LevelError default: lvl = slog.LevelInfo } hopts := &slog.HandlerOptions{Level: lvl} var h slog.Handler if strings.EqualFold(o.Format, "text") { h = slog.NewTextHandler(os.Stderr, hopts) } else { h = slog.NewJSONHandler(os.Stderr, hopts) } l := slog.New(h) slog.SetDefault(l) return l }