diff options
author | appilon <apilon@hashicorp.com> | 2019-02-27 16:43:31 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-27 16:43:31 -0500 |
commit | 844b5a68d8af4791755b8f0ad293cc99f5959183 (patch) | |
tree | 255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/hashicorp/terraform/helper/logging | |
parent | 303b299eeb6b06e939e35905e4b34cb410dd9dc3 (diff) | |
parent | 15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (diff) | |
download | terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.tar.gz terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.tar.zst terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.zip |
Merge pull request #27 from terraform-providers/go-modules-2019-02-22
[MODULES] Switch to Go Modules
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/helper/logging')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/helper/logging/logging.go | 8 | ||||
-rw-r--r-- | vendor/github.com/hashicorp/terraform/helper/logging/transport.go | 21 |
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 | ||
21 | var validLevels = []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR"} | 21 | var 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. |
24 | func LogOutput() (logOutput io.Writer, err error) { | 24 | func 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 | ||
92 | func isValidLogLevel(level string) bool { | 92 | func 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 @@ | |||
1 | package logging | 1 | package logging |
2 | 2 | ||
3 | import ( | 3 | import ( |
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 | ||
9 | type transport struct { | 12 | type 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. | ||
50 | func 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 | |||
45 | const logReqMsg = `%s API Request Details: | 62 | const logReqMsg = `%s API Request Details: |
46 | ---[ REQUEST ]--------------------------------------- | 63 | ---[ REQUEST ]--------------------------------------- |
47 | %s | 64 | %s |