1
0
mirror of https://github.com/go-kratos/kratos.git synced 2024-12-30 21:19:57 +02:00
kratos/log/helper_test.go
Tony Chen d78eb3ee4b
log: add level printer (#918)
* add level printer

* fix helper args

* fix test

* Update README.md
2021-05-17 16:34:28 +08:00

46 lines
941 B
Go

package log
import (
"io/ioutil"
"testing"
)
func TestHelper(t *testing.T) {
logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller)
log := NewHelper(logger)
log.Log(LevelDebug, "msg", "test debug")
log.Debug("test debug")
log.Debugf("test %s", "debug")
log.Debugw("log", "test debug")
}
func TestHelperLevel(t *testing.T) {
log := NewHelper(DefaultLogger)
log.Debug("test debug")
log.Info("test info")
log.Warn("test warn")
log.Error("test error")
}
func BenchmarkHelperPrint(b *testing.B) {
log := NewHelper(NewStdLogger(ioutil.Discard))
for i := 0; i < b.N; i++ {
log.Debug("test")
}
}
func BenchmarkHelperPrintf(b *testing.B) {
log := NewHelper(NewStdLogger(ioutil.Discard))
for i := 0; i < b.N; i++ {
log.Debugf("%s", "test")
}
}
func BenchmarkHelperPrintw(b *testing.B) {
log := NewHelper(NewStdLogger(ioutil.Discard))
for i := 0; i < b.N; i++ {
log.Debugw("key", "value")
}
}