pull/1053/head
chenzhihui 4 years ago
parent ba2607530d
commit f92d4742bb
  1. 27
      log/filter.go
  2. 4
      log/value.go

@ -57,7 +57,7 @@ func NewFilter(logger Logger, opts ...FilterOption) *Filter {
return &options
}
// Log Print log by level and keyvals
// Log Print log by level and keyvals.
func (f *Filter) Log(level Level, keyvals ...interface{}) error {
if f.level > level {
return nil
@ -65,19 +65,18 @@ func (f *Filter) Log(level Level, keyvals ...interface{}) error {
if f.filter != nil && f.filter(level, keyvals...) {
return nil
}
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] = "***"
}
for i := 0; i < len(keyvals); i += 2 {
iv := i + 1
if iv >= len(keyvals) {
continue
}
k := keyvals[i]
v := keyvals[iv]
if _, ok := f.key[k]; ok {
keyvals[i+1] = "***"
}
if _, ok := f.value[v]; ok {
keyvals[i+1] = "***"
}
}
return f.logger.Log(level, keyvals...)

@ -33,11 +33,11 @@ func Value(ctx context.Context, v interface{}) interface{} {
func Caller(depth int) Valuer {
return func(context.Context) interface{} {
_, file, line, _ := runtime.Caller(depth)
if strings.LastIndex(file, "/log/helper.go") > 0 {
if strings.LastIndex(file, "/log/filter.go") > 0 {
depth++
_, file, line, _ = runtime.Caller(depth)
}
if strings.LastIndex(file, "/log/filter.go") > 0 {
if strings.LastIndex(file, "/log/helper.go") > 0 {
depth++
_, file, line, _ = runtime.Caller(depth)
}

Loading…
Cancel
Save