From 8341b7f914eff7997c5b898c8c352a75b742a140 Mon Sep 17 00:00:00 2001 From: trinity-1686a Date: Fri, 20 Mar 2026 20:22:34 +0000 Subject: [PATCH] log api error in one self-sufficient line (fix #1381) (#1390) this makes it more easy to correlate an error with the request that caused it. This can be helpful during debugging, or when setting up some sort of automation based on log content Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/1390 Reviewed-by: Alex Reviewed-by: maximilien Co-authored-by: trinity-1686a Co-committed-by: trinity-1686a --- src/api/common/generic_server.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/api/common/generic_server.rs b/src/api/common/generic_server.rs index 20903938..8a09d647 100644 --- a/src/api/common/generic_server.rs +++ b/src/api/common/generic_server.rs @@ -163,10 +163,11 @@ impl ApiServer { .map(|k| format!("(key {k}) ")) .unwrap_or_default(); + let method = req.method().clone(); if A::API_NAME == "admin" && (uri.path() == "/health" || uri.path() == "/metrics") { - debug!("{source} {key}{} {uri}", req.method()); + debug!("{source} {key}{method} {uri}"); } else { - info!("{source} {key}{} {uri}", req.method()); + info!("{source} {key}{method} {uri}"); } debug!("{:?}", req); @@ -202,9 +203,17 @@ impl ApiServer { let http_error = http_error_builder.body(body)?; if e.http_status_code().is_server_error() { - warn!("Response: error {}, {}", e.http_status_code(), e); + warn!( + "error {}, {} in response to {source} {key}{method} {uri}", + e.http_status_code(), + e + ); } else { - info!("Response: error {}, {}", e.http_status_code(), e); + info!( + "error {}, {} in response to {source} {key}{method} {uri}", + e.http_status_code(), + e + ); } Ok(http_error .map(|body| BoxBody::new(body.map_err(|_: Infallible| unreachable!()))))