From db01d33b0fc978f54d70426b30985b17b1cf5d9a Mon Sep 17 00:00:00 2001 From: Mo8it Date: Sun, 26 Feb 2023 16:47:29 +0100 Subject: [PATCH] Use instrument --- src/mailer.rs | 3 +++ src/routes.rs | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/mailer.rs b/src/mailer.rs index bd2e668..31c327d 100644 --- a/src/mailer.rs +++ b/src/mailer.rs @@ -91,6 +91,7 @@ impl Mailer { .zip(persistent_field_contents.custom.iter()) .map(|(label, content)| format!("{label}:\n{content}\n\n\n")) .fold(default_fields_content, |acc, s| acc + &s); + info!("Email body:\n{}", body.trim_end()); let email = self .message_builder @@ -105,6 +106,8 @@ impl Mailer { .await .context("Failed to send email!")?; + info!("Successful contact form submission"); + Ok(()) } } diff --git a/src/routes.rs b/src/routes.rs index cc6a5d4..418959f 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -8,7 +8,7 @@ use std::{ collections::HashMap, sync::{Arc, Mutex}, }; -use tracing::{error, info}; +use tracing::{error, info, instrument}; use crate::{ captcha_solutions::CaptchaSolutions, @@ -59,11 +59,12 @@ pub fn render_contact_form(params: ContactFormParams<'_>) -> Result>, State(captcha_solutions): State>>, ) -> Result { - info!("Visited get(index)"); + info!("GET /"); render_contact_form(ContactFormParams { config, @@ -74,12 +75,15 @@ pub async fn index( } /// Submit handler. +#[instrument(skip_all)] pub async fn submit( State(config): State>, State(captcha_solutions): State>>, State(mailer): State>, Form(map): Form>, ) -> Result { + info!("POST /"); + let form = ContactForm::from_map(map, &config.custom_fields)?; let right_captcha_answer = captcha_solutions @@ -114,8 +118,6 @@ pub async fn submit( /// Called on successful contact form submission. pub fn success(config: Arc) -> Result { - info!("Successful contact form submission"); - // Initialize template. let template = templates::Success { base: templates::Base {