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.
 
 
 
 
 
 

43 lines
1.0 KiB

package log_test
import (
"bytes"
"io/ioutil"
"strings"
"testing"
"github.com/tendermint/tendermint/libs/log"
)
func TestLoggerLogsItsErrors(t *testing.T) {
var buf bytes.Buffer
logger := log.NewTMLogger(&buf)
logger.Info("foo", "baz baz", "bar")
msg := strings.TrimSpace(buf.String())
if !strings.Contains(msg, "foo") {
t.Errorf("expected logger msg to contain ErrInvalidKey, got %s", msg)
}
}
func BenchmarkTMLoggerSimple(b *testing.B) {
benchmarkRunner(b, log.NewTMLogger(ioutil.Discard), baseInfoMessage)
}
func BenchmarkTMLoggerContextual(b *testing.B) {
benchmarkRunner(b, log.NewTMLogger(ioutil.Discard), withInfoMessage)
}
func benchmarkRunner(b *testing.B, logger log.Logger, f func(log.Logger)) {
lc := logger.With("common_key", "common_value")
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
f(lc)
}
}
var (
baseInfoMessage = func(logger log.Logger) { logger.Info("foo_message", "foo_key", "foo_value") }
withInfoMessage = func(logger log.Logger) { logger.With("a", "b").Info("c", "d", "f") }
)