lotus/node/modules/tracer/json_transport.go

37 lines
644 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,
}
}
func (jtt *jsonTracerTransport) Transport(event TracerTransportEvent) error {
var e interface{}
if event.lotusTraceEvent != nil {
e = *event.lotusTraceEvent
} else if event.pubsubTraceEvent != nil {
e = *event.pubsubTraceEvent
} else {
return nil
}
jsonEvent, err := json.Marshal(e)
if err != nil {
return fmt.Errorf("error while marshaling event: %s", err)
}
_, err = jtt.out.Write(jsonEvent)
2021-09-15 11:41:03 +00:00
return err
}