You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
634 B
32 lines
634 B
2 years ago
|
package log
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestNewFilter(t *testing.T) {
|
||
|
logger := With(DefaultLogger,
|
||
|
//"ts", DefaultTimestamp, "caller", DefaultCaller
|
||
|
)
|
||
|
log := NewHelper(NewFilter(logger,
|
||
|
FilterKey("username"),
|
||
|
FilterValue("hello"),
|
||
|
FilterFunc(func(level Level, keyvals ...any) bool {
|
||
|
if level == LevelWarn {
|
||
|
return true
|
||
|
}
|
||
|
for i := 0; i < len(keyvals); i++ {
|
||
|
if keyvals[i] == "password" {
|
||
|
keyvals[i+1] = fuzzyStr
|
||
|
}
|
||
|
}
|
||
|
return false
|
||
|
}),
|
||
|
))
|
||
|
log.Log(LevelDebug, "msg", "test debug")
|
||
|
log.Info("hello")
|
||
|
log.Infow("password", "123456")
|
||
|
log.Infow("username", "kratos")
|
||
|
log.Warn("warn log")
|
||
|
}
|