Skip to content

Commit

Permalink
Use @timestamp as time key in logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmcconnell committed Mar 27, 2024
1 parent 58e0d77 commit a324ed5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion internal/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit a324ed5

Please sign in to comment.