Add structured logging with log/slog
Replace fmt.Printf logging calls with slog.Info/slog.Error for structured JSON output to stderr. Add internal/log package to initialize the default slog handler from the config log level. Fix .gitignore to only ignore the binary at the repo root, not the cmd/eng-pad-server directory. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
23
internal/log/log.go
Normal file
23
internal/log/log.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Init(level string) {
|
||||
var lvl slog.Level
|
||||
switch strings.ToLower(level) {
|
||||
case "debug":
|
||||
lvl = slog.LevelDebug
|
||||
case "warn":
|
||||
lvl = slog.LevelWarn
|
||||
case "error":
|
||||
lvl = slog.LevelError
|
||||
default:
|
||||
lvl = slog.LevelInfo
|
||||
}
|
||||
handler := slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: lvl})
|
||||
slog.SetDefault(slog.New(handler))
|
||||
}
|
||||
Reference in New Issue
Block a user