Merge pull request #15816 from hashicorp/jbardin/plugin-logger

specify a logger for go-plugin
This commit is contained in:
James Bardin 2017-08-15 14:55:11 -04:00 committed by GitHub
commit 3dd0f93aed
1 changed files with 9 additions and 0 deletions

View File

@ -1,8 +1,10 @@
package plugin package plugin
import ( import (
"os"
"os/exec" "os/exec"
hclog "github.com/hashicorp/go-hclog"
plugin "github.com/hashicorp/go-plugin" plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/terraform/plugin/discovery" "github.com/hashicorp/terraform/plugin/discovery"
) )
@ -10,11 +12,18 @@ import (
// ClientConfig returns a configuration object that can be used to instantiate // ClientConfig returns a configuration object that can be used to instantiate
// a client for the plugin described by the given metadata. // a client for the plugin described by the given metadata.
func ClientConfig(m discovery.PluginMeta) *plugin.ClientConfig { func ClientConfig(m discovery.PluginMeta) *plugin.ClientConfig {
logger := hclog.New(&hclog.LoggerOptions{
Name: "plugin",
Level: hclog.Trace,
Output: os.Stderr,
})
return &plugin.ClientConfig{ return &plugin.ClientConfig{
Cmd: exec.Command(m.Path), Cmd: exec.Command(m.Path),
HandshakeConfig: Handshake, HandshakeConfig: Handshake,
Managed: true, Managed: true,
Plugins: PluginMap, Plugins: PluginMap,
Logger: logger,
} }
} }