@@ -39,12 +39,14 @@ func (h *HTTPRoundTripLogger) RoundTrip(req *http.Request) (*http.Response, erro
3939 return nil, err
4040 }
4141
42− slog.Debug(
43− "HTTP Request",
44− "method", req.Method,
45− "url", req.URL,
46− "body", bodyToString(save),
47− )
42+ if slog.Default().Enabled(req.Context(), slog.LevelDebug) {
43+ slog.Debug(
44+ "HTTP Request",
45+ "method", req.Method,
46+ "url", req.URL,
47+ "body", bodyToString(save),
48+ )
49+ }
4850
4951 start := time.Now()
5052 resp, err := h.Transport.RoundTrip(req)
@@ -61,16 +63,18 @@ func (h *HTTPRoundTripLogger) RoundTrip(req *http.Request) (*http.Response, erro
6163 }
6264
6365 save, resp.Body, err = drainBody(resp.Body)
64− slog.Debug(
65− "HTTP Response",
66− "status_code", resp.StatusCode,
67− "status", resp.Status,
68− "headers", formatHeaders(resp.Header),
69− "body", bodyToString(save),
70− "content_length", resp.ContentLength,
71− "duration_ms", duration.Milliseconds(),
72− "error", err,
73− )
66+ if slog.Default().Enabled(req.Context(), slog.LevelDebug) {
67+ slog.Debug(
68+ "HTTP Response",
69+ "status_code", resp.StatusCode,
70+ "status", resp.Status,
71+ "headers", formatHeaders(resp.Header),
72+ "body", bodyToString(save),
73+ "content_length", resp.ContentLength,
74+ "duration_ms", duration.Milliseconds(),
75+ "error", err,
76+ )
77+ }
7478 return resp, err
7579}
7680
@@ -84,7 +88,7 @@ func bodyToString(body io.ReadCloser) string {
8488 return ""
8589 }
8690 var b bytes.Buffer
87− if json.Compact(&b, bytes.TrimSpace(src)) != nil {
91+ if json.Indent(&b, bytes.TrimSpace(src), "", " ") != nil {
8892 // not json probably
8993 return string(src)
9094 }