lotus/node/modules/tracer/json_transport.go

37 lines
630 B
Go
Raw Normal View History

2021-09-15 11:41:03 +00:00
package tracer
import (
"encoding/json"
"fmt"
2021-09-15 11:41:03 +00:00
"os"
)
type jsonTracerTransport struct {
out *os.File
}
func NewJsonTracerTransport(out *os.File) TracerTransport {
return &jsonTracerTransport{
out: out,
}
}
2021-09-15 14:16:12 +00:00
func (jtt *jsonTracerTransport) Transport(evt TracerTransportEvent) error {
var e interface{}
2021-09-15 14:16:12 +00:00
if evt.lotusTraceEvent != nil {
e = *evt.lotusTraceEvent
} else if evt.pubsubTraceEvent != nil {
e = *evt.pubsubTraceEvent
} else {
return nil
}
2021-09-15 14:16:12 +00:00
jsonEvt, err := json.Marshal(e)
if err != nil {
return fmt.Errorf("error while marshaling event: %s", err)
}
2021-09-15 14:16:12 +00:00
_, err = jtt.out.Write(jsonEvt)
2021-09-15 11:41:03 +00:00
return err
}