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