improve plugin logging

This commit is contained in:
Determinant 2020-06-23 18:33:57 -04:00
parent 7591e93e08
commit d40fbe8f75
2 changed files with 15 additions and 9 deletions

1
go.mod
View File

@ -20,6 +20,7 @@ require (
github.com/gorilla/mux v1.7.4
github.com/gorilla/rpc v1.2.0
github.com/gorilla/websocket v1.4.2
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd
github.com/hashicorp/go-plugin v1.3.0
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/huin/goupnp v1.0.0

View File

@ -5,13 +5,12 @@ package rpcchainvm
import (
"errors"
"github.com/ava-labs/gecko/snow"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
"io/ioutil"
"log"
"os/exec"
"github.com/hashicorp/go-plugin"
"github.com/ava-labs/gecko/snow"
)
var (
@ -33,12 +32,18 @@ func (f *Factory) New(ctx *snow.Context) (interface{}, error) {
},
}
if ctx != nil {
// disable go-plugin logging (since it is not controlled by Gecko's own
// logging facility)
log.SetOutput(ioutil.Discard)
log.SetOutput(ctx.Log)
config.Stderr = ctx.Log
config.SyncStdout = ctx.Log
config.SyncStderr = ctx.Log
config.Logger = hclog.New(&hclog.LoggerOptions{
Output: ctx.Log,
Level: hclog.Info,
})
} else {
log.SetOutput(ioutil.Discard)
config.Stderr = ioutil.Discard
config.Logger = hclog.New(&hclog.LoggerOptions{
Output: ioutil.Discard,
})
}
client := plugin.NewClient(config)