Skip to content

Commit

Permalink
set log level from non-hclog plugins
Browse files Browse the repository at this point in the history
Most plugins using go-plugin were previously using the convention of
prefixing log lines with the log level as `[LEVEL]`. Use these prefixes
if available to set the log level.
  • Loading branch information
jbardin committed Mar 22, 2019
1 parent f4c738c commit 08a5c73
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,22 @@ func (c *Client) logStderr(r io.Reader) {
entry, err := parseJSON(line)
// If output is not JSON format, print directly to Debug
if err != nil {
l.Debug(string(line))
// Attempt to infer the desired log level from the commonly used
// string prefixes
switch line := string(line); {
case strings.HasPrefix("[TRACE]", line):
l.Trace(line)
case strings.HasPrefix("[DEBUG]", line):
l.Debug(line)
case strings.HasPrefix("[INFO]", line):
l.Info(line)
case strings.HasPrefix("[WARN]", line):
l.Warn(line)
case strings.HasPrefix("[ERROR]", line):
l.Error(line)
default:
l.Debug(line)
}
} else {
out := flattenKVPairs(entry.KVPairs)

Expand Down

0 comments on commit 08a5c73

Please sign in to comment.