Update logging vendor.

Update the vendored version of our logging helper, so we get requests
printed.
This commit is contained in:
Paddy Carver 2018-08-31 10:13:52 -07:00
parent e6af1c2a7d
commit f946490db2
2 changed files with 22 additions and 5 deletions

View File

@ -1,9 +1,12 @@
package logging
import (
"bytes"
"encoding/json"
"log"
"net/http"
"net/http/httputil"
"strings"
)
type transport struct {
@ -15,7 +18,7 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
if IsDebugOrHigher() {
reqData, err := httputil.DumpRequestOut(req, true)
if err == nil {
log.Printf("[DEBUG] "+logReqMsg, t.name, string(reqData))
log.Printf("[DEBUG] "+logReqMsg, t.name, prettyPrintJsonLines(reqData))
} else {
log.Printf("[ERROR] %s API Request error: %#v", t.name, err)
}
@ -29,7 +32,7 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
if IsDebugOrHigher() {
respData, err := httputil.DumpResponse(resp, true)
if err == nil {
log.Printf("[DEBUG] "+logRespMsg, t.name, string(respData))
log.Printf("[DEBUG] "+logRespMsg, t.name, prettyPrintJsonLines(respData))
} else {
log.Printf("[ERROR] %s API Response error: %#v", t.name, err)
}
@ -42,6 +45,20 @@ func NewTransport(name string, t http.RoundTripper) *transport {
return &transport{name, t}
}
// prettyPrintJsonLines iterates through a []byte line-by-line,
// transforming any lines that are complete json into pretty-printed json.
func prettyPrintJsonLines(b []byte) string {
parts := strings.Split(string(b), "\n")
for i, p := range parts {
if b := []byte(p); json.Valid(b) {
var out bytes.Buffer
json.Indent(&out, b, "", " ")
parts[i] = out.String()
}
}
return strings.Join(parts, "\n")
}
const logReqMsg = `%s API Request Details:
---[ REQUEST ]---------------------------------------
%s

6
vendor/vendor.json vendored
View File

@ -633,10 +633,10 @@
"versionExact": "v0.11.2"
},
{
"checksumSHA1": "BAXV9ruAyno3aFgwYI2/wWzB2Gc=",
"checksumSHA1": "j8XqkwLh2W3r3i6wnCRmve07BgI=",
"path": "github.com/hashicorp/terraform/helper/logging",
"revision": "41e50bd32a8825a84535e353c3674af8ce799161",
"revisionTime": "2018-04-10T16:50:42Z",
"revision": "6dfc4d748de9cda23835bc5704307ed45e839622",
"revisionTime": "2018-08-15T22:00:39Z",
"version": "v0.11.2",
"versionExact": "v0.11.2"
},