diff --git a/backend/src/app.rs b/backend/src/app.rs index 453561a..8e5b69e 100644 --- a/backend/src/app.rs +++ b/backend/src/app.rs @@ -21,7 +21,7 @@ use tower_http::{ services::{ServeDir, ServeFile}, trace::TraceLayer, }; -use tracing::{Level, event}; +use tracing::warn; use crate::{ config::Config, @@ -422,13 +422,13 @@ async fn get_current_user( match connection.load_user(user_id).await { Ok(user) => user, Err(error) => { - event!(Level::WARN, "Error during authentication: {}", error); + warn!("Error during authentication: {}", error); None } } } Err(error) => { - event!(Level::WARN, "Error during authentication: {}", error); + warn!("Error during authentication: {}", error); None } }, diff --git a/backend/src/data/backup.rs b/backend/src/data/backup.rs index 2f58037..3cb376a 100644 --- a/backend/src/data/backup.rs +++ b/backend/src/data/backup.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use async_compression::tokio::bufread::GzipEncoder; use chrono::{NaiveTime, TimeDelta}; use tokio::{fs::File, io::BufReader}; -use tracing::{Level, event}; +use tracing::{debug, error, info}; use super::db; @@ -27,7 +27,7 @@ where if time_to_wait < TimeDelta::zero() { time_to_wait += TimeDelta::days(1); } - event!(Level::DEBUG, "Backup in {}s", time_to_wait.num_seconds()); + debug!("Backup in {}s", time_to_wait.num_seconds()); tokio::time::sleep(time_to_wait.to_std().unwrap()).await; start(&db_connection, &path).await; @@ -46,14 +46,13 @@ where async fn start(db_connection: &db::Connection, path: &PathBuf) { let path_compressed = path.with_extension("sqlite.gz"); - event!( - Level::INFO, + info!( "Starting backup process to {}...", path_compressed.display() ); if let Err(error) = db_connection.backup(&path).await { - event!(Level::ERROR, "Error when backing up database: {}", error); + error!("Error when backing up database: {}", error); } // Compress the backup file. @@ -64,36 +63,20 @@ async fn start(db_connection: &db::Connection, path: &PathBuf) { match File::create(&path_compressed).await { Ok(mut file_output) => { if let Err(error) = tokio::io::copy(&mut encoder, &mut file_output).await { - event!( - Level::ERROR, - "Error when compressing backup file: {}", - error - ); + error!("Error when compressing backup file: {}", error); } else if let Err(error) = std::fs::remove_file(path) { - event!( - Level::ERROR, - "Error when removing uncompressed backup file: {}", - error - ); + error!("Error when removing uncompressed backup file: {}", error); } else { - event!(Level::INFO, "Backup done: {}", path_compressed.display()); + info!("Backup done: {}", path_compressed.display()); } } Err(error) => { - event!( - Level::ERROR, - "Error when creating compressed backup file: {}", - error - ); + error!("Error when creating compressed backup file: {}", error); } } } Err(error) => { - event!( - Level::ERROR, - "Error when opening backup file for compression: {}", - error - ); + error!("Error when opening backup file for compression: {}", error); } } } diff --git a/backend/src/data/db/mod.rs b/backend/src/data/db/mod.rs index 10b9553..d6f02b0 100644 --- a/backend/src/data/db/mod.rs +++ b/backend/src/data/db/mod.rs @@ -11,7 +11,7 @@ use sqlx::{ Pool, Sqlite, Transaction, sqlite::{SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions, SqliteSynchronous}, }; -use tracing::{Level, event}; +use tracing::info; use crate::consts; @@ -149,7 +149,7 @@ WHERE [type] = 'table' AND [name] = 'Version' let next_version = current_version + 1; if next_version <= CURRENT_DB_VERSION { - event!(Level::INFO, "Update to version {}...", next_version); + info!("Update to version {}...", next_version); } async fn update_version(to_version: u32, tx: &mut Transaction<'_, Sqlite>) -> Result<()> { @@ -164,7 +164,7 @@ WHERE [type] = 'table' AND [name] = 'Version' fn ok(updated: bool) -> Result { if updated { - event!(Level::INFO, "Version updated"); + info!("Version updated"); } Ok(updated) } diff --git a/backend/src/email.rs b/backend/src/email.rs index db83a67..a59c5bb 100644 --- a/backend/src/email.rs +++ b/backend/src/email.rs @@ -2,7 +2,7 @@ use lettre::{ AsyncTransport, Message, Tokio1Executor, transport::smtp::{AsyncSmtpTransport, authentication::Credentials}, }; -use tracing::{Level, event}; +use tracing::error; use crate::consts; @@ -43,7 +43,7 @@ pub async fn send_email( .build(); if let Err(error) = mailer.send(email).await { - event!(Level::ERROR, "Error when sending E-mail: {}", &error); + error!("Error when sending E-mail: {}", &error); } Ok(()) diff --git a/backend/src/main.rs b/backend/src/main.rs index d1eb736..09a65c7 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -4,7 +4,7 @@ use std::{net::SocketAddr, path::Path}; use clap::Parser; use tokio::signal; -use tracing::{Level, event}; +use tracing::{error, info}; use recipes::{ app, config, consts, @@ -17,17 +17,17 @@ async fn main() -> Result<(), Box> { let config = config::load(); let log = Log::new_to_directory(&config.logs_directory); - event!(Level::INFO, "Configuration: {:?}", config); + info!("Configuration: {:?}", config); if !process_args(&config.database_directory).await { return Ok(()); } - event!(Level::INFO, "Starting Recipes as web server..."); + info!("Starting Recipes as web server..."); let db_connection = db::Connection::new(&config.database_directory) .await - .inspect_err(|err| event!(Level::ERROR, "Unable to connect to the database: {}", err))?; + .inspect_err(|err| error!("Unable to connect to the database: {}", err))?; if let Some(backup_time) = config.backup_time { backup::start_task( @@ -36,7 +36,7 @@ async fn main() -> Result<(), Box> { backup_time, ); } else { - event!(Level::INFO, "Backups disabled by config"); + info!("Backups disabled by config"); } let port = config.port; @@ -56,7 +56,7 @@ async fn main() -> Result<(), Box> { .with_graceful_shutdown(shutdown_signal()) .await?; - event!(Level::INFO, "Recipes stopped"); + info!("Recipes stopped"); Ok(()) } @@ -105,16 +105,13 @@ where match db::Connection::new(database_directory).await { Ok(con) => { if let Err(error) = con.execute_file("sql/data_test.sql").await { - event!(Level::ERROR, "{}", error); + error!("{}", error); } - event!( - Level::INFO, - "A new test database has been created successfully" - ); + info!("A new test database has been created successfully"); } Err(error) => { - event!(Level::ERROR, "{}", error); + error!("{}", error); } } diff --git a/backend/src/services/user.rs b/backend/src/services/user.rs index cde852e..a0782f7 100644 --- a/backend/src/services/user.rs +++ b/backend/src/services/user.rs @@ -17,7 +17,7 @@ use chrono::Duration; use lettre::Address; use serde::Deserialize; use strum_macros::Display; -use tracing::{Level, event}; +use tracing::{error, warn}; use crate::{ app::{AppState, Context, Result}, @@ -94,11 +94,9 @@ pub async fn sign_up_post( form_data: &SignUpFormData, context: Context, ) -> Result { - event!( - Level::WARN, + warn!( "Unable to sign up with email {}: {}", - form_data.email, - error + form_data.email, error ); let invalid_password_mess = &context.tr.tp( @@ -213,8 +211,7 @@ pub async fn sign_up_validation( ) -> Result<(CookieJar, impl IntoResponse)> { let mut jar = CookieJar::from_headers(&headers); if let Some(ref user) = context.user { - event!( - Level::WARN, + warn!( "Unable to validate: user already logged. Email: {}", user.email ); @@ -261,11 +258,7 @@ pub async fn sign_up_validation( )) } db::user::ValidationResult::ValidationExpired => { - event!( - Level::WARN, - "Unable to validate: validation expired. Token: {}", - token - ); + warn!("Unable to validate: validation expired. Token: {}", token); Ok(( jar, Html( @@ -279,11 +272,7 @@ pub async fn sign_up_validation( )) } db::user::ValidationResult::UnknownUser => { - event!( - Level::WARN, - "Unable to validate: unknown user. Token: {}", - token - ); + warn!("Unable to validate: unknown user. Token: {}", token); Ok(( jar, Html( @@ -299,7 +288,7 @@ pub async fn sign_up_validation( } } None => { - event!(Level::WARN, "Unable to validate: no token provided"); + warn!("Unable to validate: no token provided"); Ok(( jar, Html( @@ -356,11 +345,9 @@ pub async fn sign_in_post( .await? { error @ db::user::SignInResult::AccountNotValidated => { - event!( - Level::WARN, + warn!( "Account not validated, email: {}: {}", - form_data.email, - error + form_data.email, error ); Ok(( jar, @@ -376,7 +363,7 @@ pub async fn sign_in_post( )) } error @ (db::user::SignInResult::UserNotFound | db::user::SignInResult::WrongPassword) => { - event!(Level::WARN, "Email: {}: {}", form_data.email, error); + warn!("Email: {}: {}", form_data.email, error); Ok(( jar, Html( @@ -564,7 +551,7 @@ pub async fn ask_reset_password_post( } } Err(error) => { - event!(Level::ERROR, "{}", error); + error!("{}", error); error_response( AskResetPasswordError::DatabaseError, &form_data.email, @@ -649,8 +636,7 @@ pub async fn reset_password_post( form_data: &ResetPasswordForm, context: Context, ) -> Result { - event!( - Level::WARN, + warn!( "Email: {}: {}", if let Some(ref user) = context.user { &user.email @@ -779,8 +765,7 @@ pub async fn edit_user_post( form_data: &EditUserForm, context: Context, ) -> Result { - event!( - Level::WARN, + warn!( "Email: {}: {}", if let Some(ref user) = context.user { &user.email @@ -978,7 +963,7 @@ pub async fn email_revalidation( )) } error @ db::user::ValidationResult::ValidationExpired => { - event!(Level::WARN, "Token: {}: {}", token, error); + warn!("Token: {}: {}", token, error); Ok(( jar, Html( @@ -992,7 +977,7 @@ pub async fn email_revalidation( )) } error @ db::user::ValidationResult::UnknownUser => { - event!(Level::WARN, "Email: {}: {}", token, error); + warn!("Email: {}: {}", token, error); Ok(( jar, Html( diff --git a/backend/src/translation.rs b/backend/src/translation.rs index 5bd28eb..3c41e31 100644 --- a/backend/src/translation.rs +++ b/backend/src/translation.rs @@ -6,7 +6,7 @@ use ron::de::from_reader; use serde::Deserialize; use strum::EnumCount; use strum_macros::EnumCount; -use tracing::{Level, event}; +use tracing::warn; use crate::consts; @@ -349,11 +349,7 @@ fn get_language_translation(code: &str) -> &'static Language { } } - event!( - Level::WARN, - "Unable to find translation for language {}", - code - ); + warn!("Unable to find translation for language {}", code); if code != DEFAULT_LANGUAGE_CODE { get_language_translation(DEFAULT_LANGUAGE_CODE)