fix log filter (#1056)

* fix log filter

Co-authored-by: Tony Chen <zhihui_chen@foxmail.com>
pull/1061/head
包子 4 years ago committed by GitHub
parent 0ff1c6f89a
commit 258e911f4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      log/filter.go
  2. 2
      log/std.go

@ -59,22 +59,24 @@ func NewFilter(logger Logger, opts ...FilterOption) *Filter {
// Log Print log by level and keyvals.
func (f *Filter) Log(level Level, keyvals ...interface{}) error {
if f.level > level {
if level < f.level {
return nil
}
if f.filter != nil && f.filter(level, keyvals...) {
return nil
}
for i := 0; i < len(keyvals); i += 2 {
if _, ok := f.key[keyvals[i]]; ok {
keyvals[i+1] = "***"
}
vi := i + 1
if vi >= len(keyvals) {
continue
}
if _, ok := f.value[keyvals[vi]]; ok {
keyvals[i+1] = "***"
if len(f.key) > 0 || len(f.value) > 0 {
for i := 0; i < len(keyvals); i += 2 {
v := i + 1
if v >= len(keyvals) {
continue
}
if _, ok := f.key[keyvals[i]]; ok {
keyvals[v] = "***"
}
if _, ok := f.value[keyvals[v]]; ok {
keyvals[v] = "***"
}
}
}
return f.logger.Log(level, keyvals...)

@ -33,7 +33,7 @@ func (l *stdLogger) Log(level Level, keyvals ...interface{}) error {
return nil
}
if len(keyvals)%2 != 0 {
keyvals = append(keyvals, "")
keyvals = append(keyvals, "KEYVALS UNPAIRED")
}
buf := l.pool.Get().(*bytes.Buffer)
buf.WriteString(level.String())

Loading…
Cancel
Save