@@ -39,12 +39,14 @@ func (h *HTTPRoundTripLogger) RoundTrip(req *http.Request) (*http.Response, erro
39 return nil, err
39 return nil, err
42+ if slog.Default().Enabled(req.Context(), slog.LevelDebug) {
42− slog.Debug(
43+ slog.Debug(
43− "HTTP Request",
44+ "HTTP Request",
44− "method", req.Method,
45+ "method", req.Method,
45− "url", req.URL,
46+ "url", req.URL,
46− "body", bodyToString(save),
47+ "body", bodyToString(save),
49 start := time.Now()
51 start := time.Now()
50 resp, err := h.Transport.RoundTrip(req)
52 resp, err := h.Transport.RoundTrip(req)
@@ -61,16 +63,18 @@ func (h *HTTPRoundTripLogger) RoundTrip(req *http.Request) (*http.Response, erro
63 save, resp.Body, err = drainBody(resp.Body)
65 save, resp.Body, err = drainBody(resp.Body)
66+ if slog.Default().Enabled(req.Context(), slog.LevelDebug) {
64− slog.Debug(
67+ slog.Debug(
65− "HTTP Response",
68+ "HTTP Response",
66− "status_code", resp.StatusCode,
69+ "status_code", resp.StatusCode,
67− "status", resp.Status,
70+ "status", resp.Status,
68− "headers", formatHeaders(resp.Header),
71+ "headers", formatHeaders(resp.Header),
69− "body", bodyToString(save),
72+ "body", bodyToString(save),
70− "content_length", resp.ContentLength,
73+ "content_length", resp.ContentLength,
71− "duration_ms", duration.Milliseconds(),
74+ "duration_ms", duration.Milliseconds(),
72− "error", err,
75+ "error", err,
74 return resp, err
78 return resp, err
@@ -84,7 +88,7 @@ func bodyToString(body io.ReadCloser) string {
86 var b bytes.Buffer
90 var b bytes.Buffer
87− if json.Compact(&b, bytes.TrimSpace(src)) != nil {
91+ if json.Indent(&b, bytes.TrimSpace(src), "", " ") != nil {
88 // not json probably
92 // not json probably
89 return string(src)
93 return string(src)