aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/terraform/helper/logging
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/helper/logging')
-rw-r--r--vendor/github.com/hashicorp/terraform/helper/logging/logging.go8
-rw-r--r--vendor/github.com/hashicorp/terraform/helper/logging/transport.go21
2 files changed, 23 insertions, 6 deletions
diff --git a/vendor/github.com/hashicorp/terraform/helper/logging/logging.go b/vendor/github.com/hashicorp/terraform/helper/logging/logging.go
index 433cd77..6bd92f7 100644
--- a/vendor/github.com/hashicorp/terraform/helper/logging/logging.go
+++ b/vendor/github.com/hashicorp/terraform/helper/logging/logging.go
@@ -18,7 +18,7 @@ const (
18 EnvLogFile = "TF_LOG_PATH" // Set to a file 18 EnvLogFile = "TF_LOG_PATH" // Set to a file
19) 19)
20 20
21var validLevels = []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR"} 21var ValidLevels = []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR"}
22 22
23// LogOutput determines where we should send logs (if anywhere) and the log level. 23// LogOutput determines where we should send logs (if anywhere) and the log level.
24func LogOutput() (logOutput io.Writer, err error) { 24func LogOutput() (logOutput io.Writer, err error) {
@@ -40,7 +40,7 @@ func LogOutput() (logOutput io.Writer, err error) {
40 40
41 // This was the default since the beginning 41 // This was the default since the beginning
42 logOutput = &logutils.LevelFilter{ 42 logOutput = &logutils.LevelFilter{
43 Levels: validLevels, 43 Levels: ValidLevels,
44 MinLevel: logutils.LogLevel(logLevel), 44 MinLevel: logutils.LogLevel(logLevel),
45 Writer: logOutput, 45 Writer: logOutput,
46 } 46 }
@@ -77,7 +77,7 @@ func LogLevel() string {
77 logLevel = strings.ToUpper(envLevel) 77 logLevel = strings.ToUpper(envLevel)
78 } else { 78 } else {
79 log.Printf("[WARN] Invalid log level: %q. Defaulting to level: TRACE. Valid levels are: %+v", 79 log.Printf("[WARN] Invalid log level: %q. Defaulting to level: TRACE. Valid levels are: %+v",
80 envLevel, validLevels) 80 envLevel, ValidLevels)
81 } 81 }
82 82
83 return logLevel 83 return logLevel
@@ -90,7 +90,7 @@ func IsDebugOrHigher() bool {
90} 90}
91 91
92func isValidLogLevel(level string) bool { 92func isValidLogLevel(level string) bool {
93 for _, l := range validLevels { 93 for _, l := range ValidLevels {
94 if strings.ToUpper(level) == string(l) { 94 if strings.ToUpper(level) == string(l) {
95 return true 95 return true
96 } 96 }
diff --git a/vendor/github.com/hashicorp/terraform/helper/logging/transport.go b/vendor/github.com/hashicorp/terraform/helper/logging/transport.go
index 4477924..bddabe6 100644
--- a/vendor/github.com/hashicorp/terraform/helper/logging/transport.go
+++ b/vendor/github.com/hashicorp/terraform/helper/logging/transport.go
@@ -1,9 +1,12 @@
1package logging 1package logging
2 2
3import ( 3import (
4 "bytes"
5 "encoding/json"
4 "log" 6 "log"
5 "net/http" 7 "net/http"
6 "net/http/httputil" 8 "net/http/httputil"
9 "strings"
7) 10)
8 11
9type transport struct { 12type transport struct {
@@ -15,7 +18,7 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
15 if IsDebugOrHigher() { 18 if IsDebugOrHigher() {
16 reqData, err := httputil.DumpRequestOut(req, true) 19 reqData, err := httputil.DumpRequestOut(req, true)
17 if err == nil { 20 if err == nil {
18 log.Printf("[DEBUG] "+logReqMsg, t.name, string(reqData)) 21 log.Printf("[DEBUG] "+logReqMsg, t.name, prettyPrintJsonLines(reqData))
19 } else { 22 } else {
20 log.Printf("[ERROR] %s API Request error: %#v", t.name, err) 23 log.Printf("[ERROR] %s API Request error: %#v", t.name, err)
21 } 24 }
@@ -29,7 +32,7 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
29 if IsDebugOrHigher() { 32 if IsDebugOrHigher() {
30 respData, err := httputil.DumpResponse(resp, true) 33 respData, err := httputil.DumpResponse(resp, true)
31 if err == nil { 34 if err == nil {
32 log.Printf("[DEBUG] "+logRespMsg, t.name, string(respData)) 35 log.Printf("[DEBUG] "+logRespMsg, t.name, prettyPrintJsonLines(respData))
33 } else { 36 } else {
34 log.Printf("[ERROR] %s API Response error: %#v", t.name, err) 37 log.Printf("[ERROR] %s API Response error: %#v", t.name, err)
35 } 38 }
@@ -42,6 +45,20 @@ func NewTransport(name string, t http.RoundTripper) *transport {
42 return &transport{name, t} 45 return &transport{name, t}
43} 46}
44 47
48// prettyPrintJsonLines iterates through a []byte line-by-line,
49// transforming any lines that are complete json into pretty-printed json.
50func prettyPrintJsonLines(b []byte) string {
51 parts := strings.Split(string(b), "\n")
52 for i, p := range parts {
53 if b := []byte(p); json.Valid(b) {
54 var out bytes.Buffer
55 json.Indent(&out, b, "", " ")
56 parts[i] = out.String()
57 }
58 }
59 return strings.Join(parts, "\n")
60}
61
45const logReqMsg = `%s API Request Details: 62const logReqMsg = `%s API Request Details:
46---[ REQUEST ]--------------------------------------- 63---[ REQUEST ]---------------------------------------
47%s 64%s