Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Commit c093bc7

Browse files
Merge pull request #154 from borchero/fix-logging
Fix logging when setting `GF_LOG=1`
2 parents 1a12415 + c9d649a commit c093bc7

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

client.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,19 @@ func (c *Client) newRequest(method, requestPath string, query url.Values, body i
181181
if body == nil {
182182
log.Printf("request (%s) to %s with no body data", method, url.String())
183183
} else {
184-
log.Printf("request (%s) to %s with body data: %s", method, url.String(), body.(*bytes.Buffer).String())
184+
reader := body.(*bytes.Reader)
185+
if reader.Len() == 0 {
186+
log.Printf("request (%s) to %s with no body data", method, url.String())
187+
} else {
188+
contents := make([]byte, reader.Len())
189+
if _, err := reader.Read(contents); err != nil {
190+
return nil, fmt.Errorf("cannot read body contents for logging: %w", err)
191+
}
192+
if _, err := reader.Seek(0, io.SeekStart); err != nil {
193+
return nil, fmt.Errorf("failed to seek body reader to start after logging: %w", err)
194+
}
195+
log.Printf("request (%s) to %s with body data: %s", method, url.String(), string(contents))
196+
}
185197
}
186198
}
187199

0 commit comments

Comments
 (0)