encode_test.go 560 B

1234567891011121314151617181920212223242526
  1. package log
  2. import (
  3. "fmt"
  4. "testing"
  5. "time"
  6. "go-common/library/log/internal"
  7. )
  8. func TestJsonEncode(t *testing.T) {
  9. enc := core.NewJSONEncoder(core.EncoderConfig{
  10. EncodeTime: core.EpochTimeEncoder,
  11. EncodeDuration: core.SecondsDurationEncoder,
  12. }, core.NewBuffer(0))
  13. KV("constant", "constant").AddTo(enc)
  14. for i := 0; i < 3; i++ {
  15. b := core.GetPool()
  16. err := enc.Encode(b, KV("no", i), KV("cat", "is cat"), KV("dog", time.Now()))
  17. if err != nil {
  18. t.Fatalf("enc.Encode error(%v)", err)
  19. }
  20. fmt.Println(string(b.Bytes()))
  21. b.Free()
  22. }
  23. }