Replies: 1 comment
-
You can very easily write a middleware that does this. Obviously this is going to be somewhat more limited than the built in logger because it can't show HTTP version, response status codes or sizes on the same line. async fn pre_logger(
req: ServiceRequest,
next: Next<impl MessageBody + 'static>,
) -> Result<ServiceResponse<impl MessageBody>, Error> {
tracing::info!(
"{} \"{} {}\" \"{}\" \"{}\"",
req.peer_addr().unwrap(),
req.method(),
req.path(),
req.headers().get("referer").and_then(|hdr| hdr.to_str().ok()).unwrap_or("-"),
req.headers().get("user-agent").and_then(|hdr| hdr.to_str().ok()).unwrap_or("-"),
);
next.call(req).await
}
App::new()
.wrap(from_fn(pre_logger)) (Uses |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It would be really nice to have an option to log requests as they're received by my app:
Beta Was this translation helpful? Give feedback.
All reactions