Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use status code for trace filter log level / message. #981

Merged
merged 1 commit into from Jul 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 32 additions & 28 deletions src/filters/trace.rs
Expand Up @@ -238,35 +238,39 @@ mod internal {
use tracing::Span;

fn finished_logger<E: IsReject>(reply: &Result<(Traced,), E>) {
match reply {
Ok((Traced(resp),)) => {
tracing::info!(target: "warp::filters::trace", status = resp.status().as_u16(), "finished processing with success");
}
Err(e) if e.status().is_server_error() => {
tracing::error!(
target: "warp::filters::trace",
status = e.status().as_u16(),
error = ?e,
"unable to process request (internal error)"
);
}
Err(e) if e.status().is_client_error() => {
tracing::warn!(
target: "warp::filters::trace",
status = e.status().as_u16(),
error = ?e,
"unable to serve request (client error)"
);
}
Err(e) => {
// Either informational or redirect
tracing::info!(
target: "warp::filters::trace",
status = e.status().as_u16(),
result = ?e,
let (status, error) = match reply {
Ok((Traced(resp),)) => (resp.status(), None),
Err(error) => (error.status(), Some(error)),
};

if status.is_success() {
tracing::info!(
target: "warp::filters::trace",
status = status.as_u16(),
"finished processing with success"
);
} else if status.is_server_error() {
tracing::error!(
target: "warp::filters::trace",
status = status.as_u16(),
error = ?error,
"unable to process request (internal error)"
);
} else if status.is_client_error() {
tracing::warn!(
target: "warp::filters::trace",
status = status.as_u16(),
error = ?error,
"unable to serve request (client error)"
);
} else {
// Either informational or redirect
tracing::info!(
target: "warp::filters::trace",
status = status.as_u16(),
error = ?error,
"finished processing with status"
);
}
);
}
}

Expand Down