Skip to content

Commit cd21714

Browse files
committed
fix(log): remove call to system time to avoid wasm integration errors
1 parent 0d4fd06 commit cd21714

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/api/log.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::action::Action;
22
use crate::http::{Addr, Header, Request, TrustedProxies};
33
use serde::{Deserialize, Serialize};
4-
use std::time::{SystemTime, UNIX_EPOCH};
54

65
#[derive(Serialize, Deserialize, Debug, Clone)]
76
pub struct Log {
@@ -45,10 +44,7 @@ pub struct LegacyLog {
4544

4645
impl Log {
4746
pub fn from_legacy(legacy: LegacyLog, proxy: String) -> Self {
48-
let now = match SystemTime::now().duration_since(UNIX_EPOCH) {
49-
Err(_) => 0,
50-
Ok(time) => time.as_millis(),
51-
};
47+
let now = chrono::Utc::now().timestamp() as u128;
5248

5349
Log {
5450
code: legacy.status_code,
@@ -86,10 +82,8 @@ impl Log {
8682
let mut referer = None;
8783
let mut content_type = None;
8884
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-
};
85+
let now = chrono::Utc::now().timestamp() as u128;
86+
let duration = now.checked_sub(request_start_time);
9387

9488
match client_ip.parse::<Addr>() {
9589
Ok(addr) => ips.push(addr.addr),

0 commit comments

Comments
 (0)