Use zap.Any for handling interface{} -> zap.Field conversion
zap.Any falls back to zap.Reflect, but is better for this case, because it first checks for the types that zap handles specially. For example, time.Duration, or error, which zap.Reflect will just treat as untyped int64 or struct objects, but zap.Any is able to detect these types and print them properly.
This commit is contained in:
committed by
Jack Christensen
parent
4a2209a1b4
commit
aafa04c156
@@ -21,7 +21,7 @@ func (pl *Logger) Log(ctx context.Context, level pgx.LogLevel, msg string, data
|
||||
fields := make([]zapcore.Field, len(data))
|
||||
i := 0
|
||||
for k, v := range data {
|
||||
fields[i] = zap.Reflect(k, v)
|
||||
fields[i] = zap.Any(k, v)
|
||||
i++
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user