From ba2607530ddac5f705c1aa99f01e589c1b516a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8C=85=E5=AD=90?= Date: Mon, 14 Jun 2021 11:02:09 +0800 Subject: [PATCH] fix log filter --- log/filter.go | 26 ++++++++++++++------------ log/helper.go | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/log/filter.go b/log/filter.go index 41d612bd3..9b87c2c2f 100644 --- a/log/filter.go +++ b/log/filter.go @@ -57,7 +57,7 @@ func NewFilter(logger Logger, opts ...FilterOption) *Filter { return &options } -// Log . +// Log Print log by level and keyvals func (f *Filter) Log(level Level, keyvals ...interface{}) error { if f.level > level { return nil @@ -65,17 +65,19 @@ func (f *Filter) Log(level Level, keyvals ...interface{}) error { if f.filter != nil && f.filter(level, keyvals...) { return nil } - for i := 0; i < len(keyvals); i += 2 { - if i > len(keyvals) { - continue - } - k := keyvals[i] - v := keyvals[i+1] - if _, ok := f.key[k]; ok { - keyvals[i+1] = "***" - } - if _, ok := f.value[v]; ok { - keyvals[i+1] = "***" + if len(keyvals)%2 == 0 { + for i := 0; i < len(keyvals); i += 2 { + if i > len(keyvals) { + continue + } + k := keyvals[i] + v := keyvals[i+1] + if _, ok := f.key[k]; ok { + keyvals[i+1] = "***" + } + if _, ok := f.value[v]; ok { + keyvals[i+1] = "***" + } } } return f.logger.Log(level, keyvals...) diff --git a/log/helper.go b/log/helper.go index 2a2aceb43..a2dabbb3f 100644 --- a/log/helper.go +++ b/log/helper.go @@ -25,7 +25,7 @@ func (h *Helper) WithContext(ctx context.Context) *Helper { } } -// Log . +// Log Print log by level and keyvals func (h *Helper) Log(level Level, keyvals ...interface{}) { h.logger.Log(level, keyvals...) }