Skip to content

Commit

Permalink
more natural structured logging
Browse files Browse the repository at this point in the history
Convert record map into slog.Group

Signed-off-by: Christian Kruse <[email protected]>
  • Loading branch information
c-kruse committed Dec 12, 2024
1 parent a3d5166 commit 58271df
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cmd/network-observer/internal/flowlog/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,13 @@ func (h *handler) handle(msg vanflow.RecordMessage) {
raw, _ := json.Marshal(record)
var out map[string]any
json.Unmarshal(raw, &out)
recordValues := make([]any, 0, len(out))
for k, v := range out {
if v == nil {
delete(out, k)
continue
}
recordValues = append(recordValues, slog.Any(k, v))
}
h.logFn(record.GetTypeMeta().String(), slog.Any("record", out), slog.String("record_id", record.Identity()), attrs)
h.logFn(record.GetTypeMeta().String(), slog.Group("record", recordValues...), attrs)
}
}

0 comments on commit 58271df

Please sign in to comment.