feat: add json log format option

Add log_format config field ("text" default, "json" for structured
JSON output) to support machine-readable logging.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-14 16:45:38 +01:00
parent a40110f2f5
commit 3ebf88fb3e
3 changed files with 14 additions and 2 deletions

View File

@@ -34,7 +34,14 @@ func main() {
level.Set(slog.LevelInfo)
}
logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: level}))
var handler slog.Handler
opts := &slog.HandlerOptions{Level: level}
if cfg.LogFormat == "json" {
handler = slog.NewJSONHandler(os.Stderr, opts)
} else {
handler = slog.NewTextHandler(os.Stderr, opts)
}
logger := slog.New(handler)
slog.SetDefault(logger)
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)