diff options
author | Stan Hu <stanhu@gmail.com> | 2020-05-08 14:56:36 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2020-05-08 14:59:35 -0700 |
commit | 1adadc2e299529e805aae3dac7c2579b88c8dae7 (patch) | |
tree | 015a7cd5140c6d4a0351972135dfcf1ef3cf4c1e /client/gitlabnet.go | |
parent | 716e30c55e893ebe2385b27f85902a789f26c6ef (diff) | |
download | gitlab-shell-1adadc2e299529e805aae3dac7c2579b88c8dae7.tar.gz |
Add HTTP status code to internal API logs
This would make it easier to filter the logs by status code.
Diffstat (limited to 'client/gitlabnet.go')
-rw-r--r-- | client/gitlabnet.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/client/gitlabnet.go b/client/gitlabnet.go index 67c48c7..7fbf63e 100644 --- a/client/gitlabnet.go +++ b/client/gitlabnet.go @@ -123,18 +123,22 @@ func (c *GitlabNetClient) DoRequest(method, path string, data interface{}) (*htt "url": request.URL.String(), "duration_ms": time.Since(start) / time.Millisecond, } + logger := log.WithFields(fields) if err != nil { - log.WithError(err).WithFields(fields).Error("Internal API unreachable") + logger.WithError(err).Error("Internal API unreachable") return nil, fmt.Errorf("Internal API unreachable") } + if response != nil { + logger = logger.WithField("status", response.StatusCode) + } if err := parseError(response); err != nil { - log.WithError(err).WithFields(fields).Error("Internal API error") + logger.WithError(err).Error("Internal API error") return nil, err } - log.WithFields(fields).Info("Finished HTTP request") + logger.Info("Finished HTTP request") return response, nil } |