From a324ed51a5076f963c7a67fd908710b9498dcee9 Mon Sep 17 00:00:00 2001 From: Kevin McConnell Date: Wed, 27 Mar 2024 17:26:27 +0000 Subject: [PATCH] Use `@timestamp` as time key in logging --- internal/cmd/run.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/cmd/run.go b/internal/cmd/run.go index 59c44e8..6752256 100644 --- a/internal/cmd/run.go +++ b/internal/cmd/run.go @@ -54,5 +54,20 @@ func (c *runCommand) setLogger() { level = slog.LevelDebug } - slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: level}))) + convertToECSNaming := func(groups []string, a slog.Attr) slog.Attr { + if a.Key == slog.TimeKey { + return slog.Attr{Key: "@timestamp", Value: a.Value} + } + return a + } + + handler := slog.NewJSONHandler( + os.Stdout, + &slog.HandlerOptions{ + Level: level, + ReplaceAttr: convertToECSNaming, + }, + ) + + slog.SetDefault(slog.New(handler)) }