fix log filter

pull/1053/head
包子 4 years ago
parent 51725f1912
commit ba2607530d
  1. 4
      log/filter.go
  2. 2
      log/helper.go

@ -57,7 +57,7 @@ func NewFilter(logger Logger, opts ...FilterOption) *Filter {
return &options return &options
} }
// Log . // Log Print log by level and keyvals
func (f *Filter) Log(level Level, keyvals ...interface{}) error { func (f *Filter) Log(level Level, keyvals ...interface{}) error {
if f.level > level { if f.level > level {
return nil return nil
@ -65,6 +65,7 @@ func (f *Filter) Log(level Level, keyvals ...interface{}) error {
if f.filter != nil && f.filter(level, keyvals...) { if f.filter != nil && f.filter(level, keyvals...) {
return nil return nil
} }
if len(keyvals)%2 == 0 {
for i := 0; i < len(keyvals); i += 2 { for i := 0; i < len(keyvals); i += 2 {
if i > len(keyvals) { if i > len(keyvals) {
continue continue
@ -78,5 +79,6 @@ func (f *Filter) Log(level Level, keyvals ...interface{}) error {
keyvals[i+1] = "***" keyvals[i+1] = "***"
} }
} }
}
return f.logger.Log(level, keyvals...) return f.logger.Log(level, keyvals...)
} }

@ -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{}) { func (h *Helper) Log(level Level, keyvals ...interface{}) {
h.logger.Log(level, keyvals...) h.logger.Log(level, keyvals...)
} }

Loading…
Cancel
Save