lotus/node/modules/tracer/json_transport.go
2021-09-15 16:16:12 +02:00

37 lines
630 B
Go

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