Skip to content

Commit

Permalink
Merge pull request #1818 from ehuss/response-log
Browse files Browse the repository at this point in the history
Reduce response logging.
  • Loading branch information
ehuss authored Jun 6, 2024
2 parents 2a42a20 + 0d0196a commit 54cd575
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,20 @@ async fn run_server(addr: SocketAddr) -> anyhow::Result<()> {
Ok::<_, hyper::Error>(hyper::service::service_fn(move |req| {
let uuid = uuid::Uuid::new_v4();
let span = tracing::span!(tracing::Level::INFO, "request", ?uuid);
// Only log the webhook responses at INFO level to avoid flooding the
// logs with huge responses. Other responses are at DEBUG.
let log_info_response = matches!(req.uri().path(), "/github-hook" | "/zulip-hook");
serve_req(req, ctx.clone(), agenda.clone())
.map(move |mut resp| {
if let Ok(resp) = &mut resp {
resp.headers_mut()
.insert("X-Request-Id", uuid.to_string().parse().unwrap());
}
log::info!("response = {:?}", resp);
if log_info_response {
log::info!("response = {resp:?}");
} else {
log::debug!("response = {resp:?}");
}
resp
})
.instrument(span)
Expand Down

0 comments on commit 54cd575

Please sign in to comment.