update log filter

pull/1053/head
包子 4 years ago
parent 58c99b2768
commit ecb0030d48
  1. 19
      log/filter.go
  2. 9
      log/filter_test.go

@ -72,23 +72,24 @@ func (h *Filter) filter(level Level, keyvals []interface{}) bool {
if len(keyvals)%2 == 0 {
for i := 0; i < len(keyvals); i += 2 {
if h.filterKey != nil {
if _, ok := h.filterKey[keyvals[i].(string)]; ok {
keyvals[i+1] = "***"
if v, ok := keyvals[i].(string); ok {
if _, ok := h.filterKey[v]; ok {
keyvals[i+1] = "***"
}
}
}
if h.filterValue != nil {
if _, ok := h.filterValue[keyvals[i].(string)]; ok {
keyvals[i] = "***"
}
if _, ok := h.filterValue[keyvals[i+1].(string)]; ok {
keyvals[i+1] = "***"
if v, ok := keyvals[i+1].(string); ok {
if _, ok := h.filterValue[v]; ok {
keyvals[i+1] = "***"
}
}
}
}
} else {
for i := 0; i < len(keyvals); i++ {
if h.filterValue != nil {
if _, ok := h.filterValue[keyvals[i].(string)]; ok {
if v, ok := keyvals[i].(string); ok {
if _, ok := h.filterValue[v]; ok {
keyvals[i] = "***"
}
}

@ -1,6 +1,7 @@
package log
import (
"fmt"
"testing"
)
@ -15,7 +16,7 @@ func TestFilterAll(t *testing.T) {
log.Log(LevelDebug, "msg", "test debug")
log.Info("hello")
log.Infow("password", "123456")
log.Infow("username", "test debug")
log.Infow("username", "kratos")
log.Warn("warn log")
}
func TestFilterLevel(t *testing.T) {
@ -58,3 +59,9 @@ func testFilterFunc(level Level, keyvals ...interface{}) bool {
}
return false
}
func TestDY(t *testing.T) {
kvs := []interface{}{}
//s := kvs[0].(string)
fmt.Println(fmt.Sprint(kvs[0]))
}
Loading…
Cancel
Save