mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-10-31 22:40:01 +00:00
[chore] include attemptno in httpclient logs (#2887)
* include request attempt number in httpclient logs * slightly nicer attempt number formatting
This commit is contained in:
parent
39b3a27c82
commit
ec334ece20
1 changed files with 10 additions and 4 deletions
|
@ -50,10 +50,16 @@ type Request struct {
|
||||||
func WrapRequest(r *http.Request) Request {
|
func WrapRequest(r *http.Request) Request {
|
||||||
var rr Request
|
var rr Request
|
||||||
rr.Request = r
|
rr.Request = r
|
||||||
rr.Entry = log.WithContext(r.Context()).
|
entry := log.WithContext(r.Context())
|
||||||
WithField("method", r.Method).
|
entry = entry.WithField("method", r.Method)
|
||||||
WithField("url", r.URL.String()).
|
entry = entry.WithField("url", r.URL.String())
|
||||||
WithField("contentType", r.Header.Get("Content-Type"))
|
if r.Body != nil {
|
||||||
|
// Only add content-type header if a request body exists.
|
||||||
|
entry = entry.WithField("contentType", r.Header.Get("Content-Type"))
|
||||||
|
}
|
||||||
|
// note our formatting library follows ptr values
|
||||||
|
entry = entry.WithField("attempt", &rr.attempts)
|
||||||
|
rr.Entry = entry
|
||||||
return rr
|
return rr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue