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.
|
|
|
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")
|
|
|
|
}
|