logger_test.go 672 B

1234567891011121314151617181920212223242526272829303132333435
  1. package logger
  2. import (
  3. "testing"
  4. "github.com/pkg/errors"
  5. )
  6. func TestJSONLogger(t *testing.T) {
  7. logger, err := NewJSONLogger(
  8. WithField("defined_key", "defined_value"),
  9. )
  10. if err != nil {
  11. t.Fatal(err)
  12. }
  13. defer logger.Sync()
  14. err = errors.New("pkg error")
  15. logger.Error("err occurs", WrapMeta(nil, NewMeta("para1", "value1"), NewMeta("para2", "value2"))...)
  16. logger.Error("err occurs", WrapMeta(err, NewMeta("para1", "value1"), NewMeta("para2", "value2"))...)
  17. }
  18. func BenchmarkJsonLogger(b *testing.B) {
  19. b.ResetTimer()
  20. logger, err := NewJSONLogger(
  21. WithField("defined_key", "defined_value"),
  22. )
  23. if err != nil {
  24. b.Fatal(err)
  25. }
  26. defer logger.Sync()
  27. }