in config/configelasticsearch/esclient.go [48:90]
func (cl *clientLogger) LogRoundTrip(requ *http.Request, resp *http.Response, clientErr error, _ time.Time, dur time.Duration) error {
zl := cl.Logger
var fields []zap.Field
if cl.logRequestBody && requ != nil && requ.Body != nil {
body := requ.Body
if requ.Header.Get("Content-Encoding") == "gzip" {
if r, err := gzip.NewReader(body); err == nil {
defer r.Close()
body = r
}
}
if b, err := io.ReadAll(body); err == nil {
fields = append(fields, zap.ByteString("request_body", b))
}
}
if cl.logResponseBody && resp != nil && resp.Body != nil {
if b, err := io.ReadAll(resp.Body); err == nil {
fields = append(fields, zap.ByteString("response_body", b))
}
}
switch {
case clientErr == nil && resp != nil:
fields = append(
fields,
zap.String("path", requ.URL.Path),
zap.String("method", requ.Method),
zap.Duration("duration", dur),
zap.String("status", resp.Status),
)
zl.Debug("Request roundtrip completed.", fields...)
case clientErr != nil:
fields = append(
fields,
zap.NamedError("reason", clientErr),
)
zl.Debug("Request failed.", fields...)
}
return nil
}