Skip to content

Commit

Permalink
Output Shopify request id when verbose logging is true
Browse files Browse the repository at this point in the history
  • Loading branch information
sshaw committed Jul 23, 2023
1 parent de43a13 commit b3dd246
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions goshopify.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ func (c *Client) logResponse(res *http.Response) {
if res == nil {
return
}

c.log.Debugf("Request Id: %s", res.Header.Get("X-Request-Id"))
c.log.Debugf("RECV %d: %s", res.StatusCode, res.Status)
c.logBody(&res.Body, "RESP: %s")
}
Expand Down
3 changes: 2 additions & 1 deletion logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestDoGetHeadersDebug(t *testing.T) {
logger := &LeveledLogger{Level: LevelDebug, stderrOverride: err, stdoutOverride: out}

reqExpected := "[DEBUG] GET: //http:%2F%2Ftest.com/foo/1\n[DEBUG] SENT: request body\n"
resExpected := "[DEBUG] RECV 200: OK\n[DEBUG] RESP: response body\n"
resExpected := "[DEBUG] Request Id: 00000000-0000-0000-0000-000000000000\n[DEBUG] RECV 200: OK\n[DEBUG] RESP: response body\n"

client := NewClient(app, "fooshop", "abcd", WithLogger(logger))

Expand Down Expand Up @@ -115,6 +115,7 @@ func TestDoGetHeadersDebug(t *testing.T) {
client.logResponse(&http.Response{
Status: http.StatusText(http.StatusOK),
StatusCode: http.StatusOK,
Header: map[string][]string{"X-Request-Id": []string{"00000000-0000-0000-0000-000000000000"}},
Body: ioutil.NopCloser(strings.NewReader("response body")),
})

Expand Down

0 comments on commit b3dd246

Please sign in to comment.