|
|
|
|
@ -21,8 +21,6 @@ import (
|
|
|
|
|
"time"
|
|
|
|
|
"unicode"
|
|
|
|
|
|
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
|
|
hclog "github.com/hashicorp/go-hclog"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@ -271,8 +269,11 @@ func NewClient(config *ClientConfig) (c *Client) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if config.Logger == nil {
|
|
|
|
|
config.Logger = hclog.Default()
|
|
|
|
|
config.Logger = config.Logger.ResetNamed("plugin")
|
|
|
|
|
config.Logger = hclog.New(&hclog.LoggerOptions{
|
|
|
|
|
Output: hclog.DefaultOutput,
|
|
|
|
|
Level: hclog.Trace,
|
|
|
|
|
Name: "plugin",
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c = &Client{
|
|
|
|
|
@ -737,16 +738,12 @@ func (c *Client) logStderr(r io.Reader) {
|
|
|
|
|
line = strings.TrimRightFunc(line, unicode.IsSpace)
|
|
|
|
|
|
|
|
|
|
l := c.logger.Named(filepath.Base(c.config.Cmd.Path))
|
|
|
|
|
// If output is not JSON format, print directly as error
|
|
|
|
|
if !isJSON(line) {
|
|
|
|
|
l.Debug("log from plugin", "entry", line)
|
|
|
|
|
|
|
|
|
|
entry, err := parseJSON(line)
|
|
|
|
|
// If output is not JSON format, print directly to Debug
|
|
|
|
|
if err != nil {
|
|
|
|
|
l.Debug(line)
|
|
|
|
|
} else {
|
|
|
|
|
// Parse JSON line received from the plugin into logEntry, and print via
|
|
|
|
|
// the client's logger
|
|
|
|
|
entry, err := parseJSON(line)
|
|
|
|
|
if err != nil {
|
|
|
|
|
l.Error("error parsing json from plugin", "error", err)
|
|
|
|
|
}
|
|
|
|
|
out := flattenKVPairs(entry.KVPairs)
|
|
|
|
|
|
|
|
|
|
l = l.With("timestamp", entry.Timestamp.Format(hclog.TimeFormat))
|
|
|
|
|
@ -773,8 +770,3 @@ func (c *Client) logStderr(r io.Reader) {
|
|
|
|
|
// Flag that we've completed logging for others
|
|
|
|
|
close(c.doneLogging)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isJSON(str string) bool {
|
|
|
|
|
var js json.RawMessage
|
|
|
|
|
return json.Unmarshal([]byte(str), &js) == nil
|
|
|
|
|
}
|
|
|
|
|
|