Get Route/Path name from function to be used for logging #2576
-
Hi! I was wondering if it is possible to extract the path name to be used for logging purposes. I have many of these created but wanted to keep track of what requests are hit the most. Is there a way to get this information? I am looking to get the string "/api/endpoint1" in the example below.
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
#[get("/api/endpoint1")]
async fn api_request(req: HttpRequest) -> Result<String> {
let path = req.path();
...
} For logging, there's a built in Logger middleware (search docs). |
Beta Was this translation helpful? Give feedback.
-
Thanks for the response @robjtede. I was able to find App::new()
.wrap_fn(|req, srv| {
let path = req.match_pattern() // Returns None
...
}
.service(a)
.service(b)
.wrap_fn(|req, srv| {
let path = req.match_pattern() // Also returns None
...
} |
Beta Was this translation helpful? Give feedback.
-
Thank you for the quick response @robjtede! That makes much more sense! |
Beta Was this translation helpful? Give feedback.
-
Exactly what I am looking for! Thank you so much for your help! |
Beta Was this translation helpful? Give feedback.
For logging, there's a built in Logger middleware (search docs).