mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-23 16:21:06 +01:00
Fix Logger time format (use rfc3339) (#867)
* Fix Logger time format (use rfc3339) * Update change log
This commit is contained in:
parent
c2d7db7e06
commit
f1764bba43
@ -15,6 +15,8 @@
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fix Logger request time format, and use rfc3339. #867
|
||||
|
||||
* Clear http requests pool on app service drop #860
|
||||
|
||||
|
||||
|
@ -53,7 +53,7 @@ use crate::HttpResponse;
|
||||
///
|
||||
/// `%a` Remote IP-address (IP-address of proxy if using reverse proxy)
|
||||
///
|
||||
/// `%t` Time when the request was started to process
|
||||
/// `%t` Time when the request was started to process (in rfc3339 format)
|
||||
///
|
||||
/// `%r` First line of request
|
||||
///
|
||||
@ -417,10 +417,7 @@ impl FormatText {
|
||||
}
|
||||
FormatText::UrlPath => *self = FormatText::Str(format!("{}", req.path())),
|
||||
FormatText::RequestTime => {
|
||||
*self = FormatText::Str(format!(
|
||||
"{:?}",
|
||||
now.strftime("[%d/%b/%Y:%H:%M:%S %z]").unwrap()
|
||||
))
|
||||
*self = FormatText::Str(format!("{}", now.rfc3339()))
|
||||
}
|
||||
FormatText::RequestHeader(ref name) => {
|
||||
let s = if let Some(val) = req.headers().get(name) {
|
||||
@ -547,4 +544,29 @@ mod tests {
|
||||
assert!(s.contains("200 1024"));
|
||||
assert!(s.contains("ACTIX-WEB"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_request_time_format() {
|
||||
let mut format = Format::new("%t");
|
||||
let req = TestRequest::default().to_srv_request();
|
||||
|
||||
let now = time::now();
|
||||
for unit in &mut format.0 {
|
||||
unit.render_request(now, &req);
|
||||
}
|
||||
|
||||
let resp = HttpResponse::build(StatusCode::OK).force_close().finish();
|
||||
for unit in &mut format.0 {
|
||||
unit.render_response(&resp);
|
||||
}
|
||||
|
||||
let render = |fmt: &mut Formatter| {
|
||||
for unit in &format.0 {
|
||||
unit.render(fmt, 1024, now)?;
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
let s = format!("{}", FormatDisplay(&render));
|
||||
assert!(s.contains(&format!("{}", now.rfc3339())));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user