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.

31 lines
630 B

2 years ago
package log
import (
"testing"
)
func TestNewFilter(t *testing.T) {
1 year ago
logger := With(DefaultLogger) //"ts", DefaultTimestamp, "caller", DefaultCaller
1 year ago
2 years ago
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")
}