Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4feefdb

Browse files
committedNov 23, 2022
support logr.KeysAndValues
This special type gets logged like an object, with attributes defined by the keys and values.
1 parent 3d259e4 commit 4feefdb

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed
 

‎zapr.go

+8
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ func zapIt(field string, val interface{}) zap.Field {
174174
if marshaler, ok := val.(logr.Marshaler); ok {
175175
field, val = invokeMarshaler(field, marshaler)
176176
}
177+
if keysAndValues, ok := val.(logr.KeysAndValues); ok {
178+
return zap.Object(field, zapcore.ObjectMarshalerFunc(func(encoder zapcore.ObjectEncoder) error {
179+
for _, keyAndValue := range keysAndValues {
180+
encoder.AddReflected(keyAndValue.Key, keyAndValue.Value)
181+
}
182+
return nil
183+
}))
184+
}
177185
return zap.Any(field, val)
178186
}
179187

0 commit comments

Comments
 (0)
Please sign in to comment.