Comments, doc comments, test names, error and log messages, CLI help, README, Makefile, CI step names and the design document are now all in English. No behaviour changes; the full suite passes under the race detector. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
42 lines
801 B
Go
42 lines
801 B
Go
// 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
|
|
}
|