Skip to content

Commit b6620dc

Browse files
committed
feat: adding RecordToAttrsMap
1 parent 64d99e2 commit b6620dc

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

attributes.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ func AttrsToMap(attrs ...slog.Attr) map[string]any {
6060
return output
6161
}
6262

63+
func RecordToAttrsMap(r slog.Record) map[string]any {
64+
attrs := make([]slog.Attr, r.NumAttrs())
65+
r.Attrs(func(attr slog.Attr) bool {
66+
attrs = append(attrs, attr)
67+
return true
68+
})
69+
70+
return AttrsToMap(attrs...)
71+
}
72+
6373
func groupValuesByKey(attrs []slog.Attr) map[string][]slog.Value {
6474
result := map[string][]slog.Value{}
6575

0 commit comments

Comments
 (0)