add log filter benchmark

pull/1053/head
包子 4 years ago
parent 7bebc58381
commit 34d6d7b90e
  1. 24
      log/filter_test.go

@ -1,6 +1,7 @@
package log
import (
"io/ioutil"
"testing"
)
@ -32,7 +33,7 @@ func TestFilterCaller(t *testing.T) {
logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller)
log := NewFilter(logger)
log.Log(LevelDebug, "msg1", "te1st debug")
logHelper := NewHelper(NewFilter(NewFilter(logger)))
logHelper := NewHelper(NewFilter(logger))
logHelper.Log(LevelDebug, "msg1", "te1st debug")
}
@ -55,6 +56,27 @@ func TestFilterFunc(t *testing.T) {
log.Infow("password", "123456")
}
func BenchmarkFilterKeys(b *testing.B) {
log := NewHelper(NewFilter(NewStdLogger(ioutil.Discard), FilterKeys("password")))
for i := 0; i < b.N; i++ {
log.Infow("password", "123456")
}
}
func BenchmarkFilterValues(b *testing.B) {
log := NewHelper(NewFilter(NewStdLogger(ioutil.Discard), FilterValues("password")))
for i := 0; i < b.N; i++ {
log.Infow("password")
}
}
func BenchmarkFilterHook(b *testing.B) {
log := NewHelper(NewFilter(NewStdLogger(ioutil.Discard), FilterHook(testFilterFunc)))
for i := 0; i < b.N; i++ {
log.Info("password","123456")
}
}
func testFilterFunc(level Level, keyvals ...interface{}) bool {
if level == LevelWarn {
return true

Loading…
Cancel
Save