diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2016-09-03 02:00:54 +0200 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2016-09-03 12:26:30 +0200 |
commit | 53b5c00e625bf700a21be1a3e2070d3b23f1bef4 (patch) | |
tree | faace67aba86121a28382a0c74fe7701e4d398b7 /rust/src/apachelog.rs | |
parent | 311a02c31e03b23cc66e662cce63e6c19d4bc662 (diff) | |
download | auth-xmppmessage-53b5c00e625bf700a21be1a3e2070d3b23f1bef4.tar.gz auth-xmppmessage-53b5c00e625bf700a21be1a3e2070d3b23f1bef4.zip |
first test version
Diffstat (limited to 'rust/src/apachelog.rs')
-rw-r--r-- | rust/src/apachelog.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/rust/src/apachelog.rs b/rust/src/apachelog.rs new file mode 100644 index 0000000..2517979 --- /dev/null +++ b/rust/src/apachelog.rs @@ -0,0 +1,45 @@ +///! Prints logging similar to apache http access.log +use std::net::IpAddr; +use conduit::{Request, Response}; +use time; + +pub struct LogEntry { + remote_ip_address: IpAddr, + remote_user: String, + request_path: String, + time: time::Tm, + status: u32, + response_size: u32, +} + +impl LogEntry { + pub fn start(req: &Request) -> LogEntry { + let entry = LogEntry { + remote_ip_address: req.remote_addr().ip(), + remote_user: String::new(), + request_path: String::from(req.path()), + time: time::now(), + status: 0, + response_size: 0, + }; + return entry + } + + pub fn done(&mut self, response: Response) -> Response { + let (status_code, _) = response.status; + self.status = status_code; + self.print(); + return response; + } + + #[inline(always)] + fn print(&self) { + println!("{} - {} - [{}] \"{}\" {} {}", + self.remote_ip_address, + self.remote_user, + time::strftime("%d/%b/%Y %T %z", &self.time).unwrap(), + self.request_path, + self.status, + self.response_size); + } +} |