@@ -7,10 +7,11 @@ use std::time::{SystemTime, UNIX_EPOCH};
77pub struct Log {
88 code : u16 ,
99 to : String ,
10- time : u64 ,
10+ time : u128 ,
1111 proxy : String ,
1212 ips : Option < Vec < String > > ,
1313 from : FromLog ,
14+ duration : Option < u128 > ,
1415}
1516
1617#[ derive( Serialize , Deserialize , Debug , Clone ) ]
@@ -46,7 +47,7 @@ impl Log {
4647 pub fn from_legacy ( legacy : LegacyLog , proxy : String ) -> Self {
4748 let now = match SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) {
4849 Err ( _) => 0 ,
49- Ok ( time) => time. as_millis ( ) as u64 ,
50+ Ok ( time) => time. as_millis ( ) ,
5051 } ;
5152
5253 Log {
@@ -65,6 +66,7 @@ impl Log {
6566 user_agent : legacy. user_agent ,
6667 content_type : None ,
6768 } ,
69+ duration : None ,
6870 }
6971 }
7072
@@ -75,7 +77,7 @@ impl Log {
7577 response_headers : & [ Header ] ,
7678 action : Option < & Action > ,
7779 proxy : & str ,
78- time : u64 ,
80+ request_start_time : u128 ,
7981 client_ip : & str ,
8082 trusted_proxies : Option < & TrustedProxies > ,
8183 ) -> Log {
@@ -84,6 +86,10 @@ impl Log {
8486 let mut referer = None ;
8587 let mut content_type = None ;
8688 let mut ips = Vec :: new ( ) ;
89+ let duration = match SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) {
90+ Err ( _) => None ,
91+ Ok ( time) => time. as_millis ( ) . checked_sub ( request_start_time) ,
92+ } ;
8793
8894 match client_ip. parse :: < Addr > ( ) {
8995 Ok ( addr) => ips. push ( addr. addr ) ,
@@ -157,9 +163,10 @@ impl Log {
157163 code,
158164 from,
159165 proxy : proxy. to_string ( ) ,
160- time,
166+ time : request_start_time ,
161167 ips : Some ( untrusted_ips. iter ( ) . map ( |ip| ip. to_string ( ) ) . collect ( ) ) ,
162168 to : location. unwrap_or_default ( ) ,
169+ duration,
163170 }
164171 }
165172}
0 commit comments