From aafa04c15675bca3c3d65d502a22e2a74b3fa664 Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Thu, 4 Jul 2019 10:21:32 +0100 Subject: [PATCH] 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. --- log/zapadapter/adapter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log/zapadapter/adapter.go b/log/zapadapter/adapter.go index ff03d9b9..ebc540aa 100644 --- a/log/zapadapter/adapter.go +++ b/log/zapadapter/adapter.go @@ -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++ }