Skip to content

Commit 715f6a2

Browse files
Merge #1364
1364: Include query string in logs r=ashleygwilliams Conduit doesn't provide any methods that give us the path and query string if present, so we have to do some additional junk to make that happen ourselves.
2 parents f7c316f + 8fda2a2 commit 715f6a2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/middleware/log_request.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! information that we care about like User-Agent and Referer
33
44
use conduit::Request;
5+
use std::fmt;
56
use std::time::Instant;
67
use super::prelude::*;
78
use util::request_header;
@@ -36,7 +37,7 @@ impl Handler for LogRequests {
3637
status={status} user_agent=\"{user_agent}\" referer=\"{referer}\"",
3738
level = level,
3839
method = req.method(),
39-
path = req.path(),
40+
path = FullPath(req),
4041
ip = request_header(req, "X-Forwarded-For"),
4142
time_ms = response_time,
4243
user_agent = request_header(req, "User-Agent"),
@@ -58,3 +59,15 @@ impl Handler for LogRequests {
5859
res
5960
}
6061
}
62+
63+
struct FullPath<'a>(&'a Request);
64+
65+
impl<'a> fmt::Display for FullPath<'a> {
66+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
67+
write!(f, "{}", self.0.path())?;
68+
if let Some(q_string) = self.0.query_string() {
69+
write!(f, "?{}", q_string)?;
70+
}
71+
Ok(())
72+
}
73+
}

0 commit comments

Comments
 (0)