Skip to content

Commit

Permalink
add zap object marshaler slice helper (#836)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulwe authored Oct 5, 2024
1 parent e29da3c commit ec3b682
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions logger/zaputil/slice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package zaputil

import "go.uber.org/zap/zapcore"

func ObjectSlice[T zapcore.ObjectMarshaler](s []T) zapcore.ArrayMarshaler {
return objectSlice[T](s)
}

type objectSlice[T zapcore.ObjectMarshaler] []T

func (a objectSlice[T]) MarshalLogArray(e zapcore.ArrayEncoder) error {
for _, o := range a {
e.AppendObject(o)
}
return nil
}

0 comments on commit ec3b682

Please sign in to comment.