pub mod auth; pub mod preferences; pub mod query; use crate::logging::logger::AuditLogger; use tracing::{error, info, warn}; /// Helper function to log errors to both console (tracing) and file (AuditLogger) /// This eliminates code duplication across route handlers pub fn log_error_async( logging: &AuditLogger, request_id: &str, error_msg: &str, context: Option<&str>, username: Option<&str>, power: Option, ) { // Log to console immediately error!("[{}] {}", request_id, error_msg); // Clone everything needed for the async task let logging = logging.clone(); let req_id = request_id.to_string(); let error_msg = error_msg.to_string(); let context = context.map(|s| s.to_string()); let username = username.map(|s| s.to_string()); // Spawn async task to log to file tokio::spawn(async move { let _ = logging .log_error( &req_id, chrono::Utc::now(), &error_msg, context.as_deref(), username.as_deref(), power, ) .await; }); } /// Helper function to log warnings to both console (tracing) and file (AuditLogger) /// This eliminates code duplication across route handlers pub fn log_warning_async( logging: &AuditLogger, request_id: &str, message: &str, context: Option<&str>, username: Option<&str>, power: Option, ) { // Log to console immediately warn!("[{}] {}", request_id, message); // Clone everything needed for the async task let logging = logging.clone(); let req_id = request_id.to_string(); let message = message.to_string(); let context = context.map(|s| s.to_string()); let username = username.map(|s| s.to_string()); // Spawn async task to log to file tokio::spawn(async move { let _ = logging .log_warning( &req_id, chrono::Utc::now(), &message, context.as_deref(), username.as_deref(), power, ) .await; }); } /// Helper function to log info messages to both console (tracing) and file (AuditLogger) /// This eliminates code duplication across route handlers pub fn log_info_async( logging: &AuditLogger, request_id: &str, message: &str, context: Option<&str>, username: Option<&str>, power: Option, ) { // Log to console immediately info!("[{}] {}", request_id, message); // Clone everything needed for the async task let logging = logging.clone(); let req_id = request_id.to_string(); let message = message.to_string(); let context = context.map(|s| s.to_string()); let username = username.map(|s| s.to_string()); // Spawn async task to log to file tokio::spawn(async move { let _ = logging .log_info( &req_id, chrono::Utc::now(), &message, context.as_deref(), username.as_deref(), power, ) .await; }); }