Move creating and opening file to json transport constructor
This commit is contained in:
parent
515925a178
commit
d067bc9f01
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
host "github.com/libp2p/go-libp2p-core/host"
|
||||
@ -368,11 +367,11 @@ func GossipSub(in GossipIn) (service *pubsub.PubSub, err error) {
|
||||
|
||||
var transports []tracer.TracerTransport
|
||||
if in.Cfg.JsonTracerFile != "" {
|
||||
out, err := os.OpenFile(in.Cfg.JsonTracerFile, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0660)
|
||||
jsonTransport, err := tracer.NewJsonTracerTransport(in.Cfg.JsonTracerFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
jsonTransport := tracer.NewJsonTracerTransport(out)
|
||||
|
||||
transports = append(transports, jsonTransport)
|
||||
}
|
||||
if in.Cfg.ElasticSearchTracer != "" {
|
||||
|
@ -10,10 +10,15 @@ type jsonTracerTransport struct {
|
||||
out *os.File
|
||||
}
|
||||
|
||||
func NewJsonTracerTransport(out *os.File) TracerTransport {
|
||||
func NewJsonTracerTransport(file string) (TracerTransport, error) {
|
||||
out, err := os.OpenFile(file, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0660)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &jsonTracerTransport{
|
||||
out: out,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (jtt *jsonTracerTransport) Transport(evt TracerTransportEvent) error {
|
||||
|
Loading…
Reference in New Issue
Block a user