From 7def38acde5121fca2ed6030c72b02c8572cf76a Mon Sep 17 00:00:00 2001 From: aveyuan Date: Wed, 8 Feb 2023 18:59:24 +0800 Subject: [PATCH] feat(log): update zap interface (#2620) --- contrib/log/zap/zap.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/contrib/log/zap/zap.go b/contrib/log/zap/zap.go index 511381f9d..094e1e654 100644 --- a/contrib/log/zap/zap.go +++ b/contrib/log/zap/zap.go @@ -19,13 +19,14 @@ func NewLogger(zlog *zap.Logger) *Logger { } func (l *Logger) Log(level log.Level, keyvals ...interface{}) error { - if len(keyvals) == 0 || len(keyvals)%2 != 0 { + keylen := len(keyvals) + if keylen == 0 || keylen%2 != 0 { l.log.Warn(fmt.Sprint("Keyvalues must appear in pairs: ", keyvals)) return nil } - var data []zap.Field - for i := 0; i < len(keyvals); i += 2 { + var data []zap.Field = make([]zap.Field, 0, (keylen/2)+1) + for i := 0; i < keylen; i += 2 { data = append(data, zap.Any(fmt.Sprint(keyvals[i]), keyvals[i+1])) }