-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add logger to axum router #773
Conversation
src/routes.rs
Outdated
@@ -111,3 +117,42 @@ where | |||
} | |||
} | |||
} | |||
|
|||
async fn log_request_response_body( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async fn log_request_response_body( | |
async fn body_logger_middleware( |
plus move everything to separate file
src/routes.rs
Outdated
Ok(response) | ||
} | ||
|
||
async fn buffer_request_body(request: Request) -> Result<Request, Response> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should only happen if sth specific is set e.g. logger option to trace
in our logger settings we can write live_compositor::routes=debug
to enable debugging in that one file, check if is there a way to provide a custom values that can enable specific log.
If above is not possible then lets enable that only when trace loggin is on
62014f9
to
db650eb
Compare
async fn buffer_request_body(request: Request) -> Result<Request, Response> { | ||
let (parts, body) = request.into_parts(); | ||
|
||
let bytes = body |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if logging is enabled then do not read/restore that body
src/middleware.rs
Outdated
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response())? | ||
.to_bytes(); | ||
|
||
if log_enabled!(target: "live_compositor::routes", Level::Debug) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is already file route that use sth that does not already exist e.g. live_compositor::log_request_body
8159d9e
to
0895584
Compare
src/middleware.rs
Outdated
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response())? | ||
.to_bytes(); | ||
|
||
trace!(target: "live_compositor::log_request_body", "Request body: {:?}", str::from_utf8(&bytes).unwrap()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- print other parts of the response too, like route or method, for response status code
- do not unwrap
Also, it would be great to try parsing requests as JSON values to remove the escaped characters
0895584
to
506f19f
Compare
506f19f
to
60e5983
Compare
No description provided.