diff --git a/Cargo.toml b/Cargo.toml index 0ea531d..7b2ed43 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,4 @@ multer = "3" futures = "0.3" tokio = { version = "1", features = ["fs"] } uuid = { version = "1", features = ["v4"] } +tracing = "0.1" diff --git a/src/public.rs b/src/public.rs index 6706116..4c33ba8 100644 --- a/src/public.rs +++ b/src/public.rs @@ -6,6 +6,7 @@ use cot::request::extractors::Path; use cot::response::{IntoResponse, Redirect, Response}; use cot::router::{Route, Router}; use serde::Deserialize; +use tracing::info; use cot::db::query; @@ -86,6 +87,33 @@ struct ThankYouTemplate<'a> { async fn landing_page(request: Request, db: Database) -> cot::Result { let lang = detect_lang(&request); + + let ua = request + .headers() + .get("user-agent") + .and_then(|v| v.to_str().ok()) + .unwrap_or("-"); + let referer = request + .headers() + .get("referer") + .and_then(|v| v.to_str().ok()) + .unwrap_or("-"); + let ip = request + .headers() + .get("x-forwarded-for") + .and_then(|v| v.to_str().ok()) + .and_then(|s| s.split(',').next()) + .map(|s| s.trim()) + .unwrap_or("-"); + + info!( + target: "landing", + ip = ip, + lang = lang.code(), + referer = referer, + ua = ua, + "landing visit" + ); let key = "contact_info".to_string(); let contact_info = query!(Setting, $key == key) .get(&db)