@@ -451,27 +451,38 @@ type loggingTransport struct {
451451 base http.RoundTripper
452452}
453453
454+ func sanitizeLogValue (value string ) string {
455+ value = strings .ReplaceAll (value , "\n " , "\\ n" )
456+ value = strings .ReplaceAll (value , "\r " , "\\ r" )
457+ return value
458+ }
459+
454460func (t * loggingTransport ) RoundTrip (req * http.Request ) (* http.Response , error ) {
455461 base := t .base
456462 if base == nil {
457463 base = http .DefaultTransport
458464 }
465+ method := sanitizeLogValue (req .Method )
466+ urlText := ""
467+ if req .URL != nil {
468+ urlText = sanitizeLogValue (req .URL .Redacted ())
469+ }
459470 resp , err := base .RoundTrip (req )
460471 if err != nil {
461- log .Printf ("iceberg-rest http %s %s failed: %v" , req . Method , req . URL , err )
472+ log .Printf ("iceberg-rest http %s %s failed: %v" , method , urlText , err )
462473 return resp , err
463474 }
464475 if resp .StatusCode >= 400 {
465476 body , readErr := io .ReadAll (io .LimitReader (resp .Body , 8192 ))
466477 _ = resp .Body .Close ()
467478 resp .Body = io .NopCloser (bytes .NewReader (body ))
468479 if readErr != nil {
469- log .Printf ("iceberg-rest http %s %s -> %d (read error: %v)" , req . Method , req . URL , resp .StatusCode , readErr )
480+ log .Printf ("iceberg-rest http %s %s -> %d (read error: %v)" , method , urlText , resp .StatusCode , readErr )
470481 } else {
471- log .Printf ("iceberg-rest http %s %s -> %d body=%s" , req . Method , req . URL , resp .StatusCode , strings .TrimSpace (string (body )))
482+ log .Printf ("iceberg-rest http %s %s -> %d body=%s" , method , urlText , resp .StatusCode , sanitizeLogValue ( strings .TrimSpace (string (body ) )))
472483 }
473484 } else {
474- log .Printf ("iceberg-rest http %s %s -> %d" , req . Method , req . URL , resp .StatusCode )
485+ log .Printf ("iceberg-rest http %s %s -> %d" , method , urlText , resp .StatusCode )
475486 }
476487 return resp , nil
477488}
0 commit comments