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.

41 lines
976 B

8 years ago
8 years ago
8 years ago
8 years ago
  1. package log_test
  2. import (
  3. "io/ioutil"
  4. "testing"
  5. "github.com/tendermint/tmlibs/log"
  6. )
  7. func TestTMLogger(t *testing.T) {
  8. t.Parallel()
  9. logger := log.NewTMLogger(ioutil.Discard)
  10. if err := logger.Info("Hello", "abc", 123); err != nil {
  11. t.Error(err)
  12. }
  13. if err := logger.With("def", "ghi").Debug(""); err != nil {
  14. t.Error(err)
  15. }
  16. }
  17. func BenchmarkTMLoggerSimple(b *testing.B) {
  18. benchmarkRunner(b, log.NewTMLogger(ioutil.Discard), baseInfoMessage)
  19. }
  20. func BenchmarkTMLoggerContextual(b *testing.B) {
  21. benchmarkRunner(b, log.NewTMLogger(ioutil.Discard), withInfoMessage)
  22. }
  23. func benchmarkRunner(b *testing.B, logger log.Logger, f func(log.Logger)) {
  24. lc := logger.With("common_key", "common_value")
  25. b.ReportAllocs()
  26. b.ResetTimer()
  27. for i := 0; i < b.N; i++ {
  28. f(lc)
  29. }
  30. }
  31. var (
  32. baseInfoMessage = func(logger log.Logger) { logger.Info("foo_message", "foo_key", "foo_value") }
  33. withInfoMessage = func(logger log.Logger) { logger.With("a", "b").Info("c", "d", "f") }
  34. )