-* Clean the old code + commit
* How to log error to journalctl or elsewhere + debug log?
* Try using WASM for all the client logic (test on editing/creating a recipe)
* Understand the example here:
.service(services::webapi::set_recipe_description)
* Add support to translations into db model.
+[ok] Clean the old code + commit
[ok] Reactivate sign up/in/out
[ok] Change all id to i64
[ok] Check cookie lifetime -> Session by default
Pool, Sqlite, Transaction,
};
use thiserror::Error;
+use tracing::{event, Level};
use crate::{
consts,
let next_version = current_version + 1;
if next_version <= CURRENT_DB_VERSION {
- println!("Update to version {}...", next_version);
+ event!(Level::INFO, "Update to version {}...", next_version);
}
async fn update_version(to_version: u32, tx: &mut Transaction<'_, Sqlite>) -> Result<()> {
fn ok(updated: bool) -> Result<bool> {
if updated {
- println!("Version updated");
+ event!(Level::INFO, "Version updated");
}
Ok(updated)
}
transport::smtp::{authentication::Credentials, AsyncSmtpTransport},
AsyncTransport, Message, Tokio1Executor,
};
+use tracing::{event, Level};
use crate::consts;
.build();
if let Err(error) = mailer.send(email).await {
- eprintln!("Error when sending E-mail:\n{:?}", &error);
+ event!(Level::ERROR, "Error when sending E-mail: {}", &error);
}
Ok(())
use chrono::prelude::*;
use clap::Parser;
use config::Config;
-use tower_http::services::ServeDir;
+use tower_http::{services::ServeDir, trace::TraceLayer};
+use tracing::{event, Level};
use data::db;
}
}
+#[cfg(debug_assertions)]
+const TRACING_LEVEL: tracing::Level = tracing::Level::DEBUG;
+
+#[cfg(not(debug_assertions))]
+const TRACING_LEVEL: tracing::Level = tracing::Level::INFO;
+
// TODO: Should main returns 'Result'?
#[tokio::main]
async fn main() {
return;
}
- println!("Starting Recipes as web server...");
+ tracing_subscriber::fmt()
+ .with_max_level(TRACING_LEVEL)
+ .init();
+
+ event!(Level::INFO, "Starting Recipes as web server...");
let config = config::load();
let port = config.port;
- println!("Configuration: {:?}", config);
-
- tracing_subscriber::fmt::init();
+ event!(Level::INFO, "Configuration: {:?}", config);
let db_connection = db::Connection::new().await.unwrap();
get(services::sign_in_get).post(services::sign_in_post),
)
.route("/signout", get(services::sign_out))
+ .layer(TraceLayer::new_for_http())
.route_layer(middleware::from_fn_with_state(
state.clone(),
user_authentication,
.authentication(token_cookie.value(), &client_ip, &client_user_agent)
.await
{
- Ok(db::AuthenticationResult::NotValidToken) => {
- // TODO: remove cookie?
- None
- }
+ Ok(db::AuthenticationResult::NotValidToken) => None,
Ok(db::AuthenticationResult::Ok(user_id)) => {
match connection.load_user(user_id).await {
Ok(user) => user,
Err(error) => {
- // TODO: Return 'Result'?
- println!("Error during authentication: {}", error);
+ event!(Level::WARN, "Error during authentication: {}", error);
None
}
}
}
Err(error) => {
- // TODO: Return 'Result'?
- println!("Error during authentication: {}", error);
+ event!(Level::WARN, "Error during authentication: {}", error);
None
}
},
match db::Connection::new().await {
Ok(con) => {
if let Err(error) = con.execute_file("sql/data_test.sql").await {
- eprintln!("{}", error);
+ event!(Level::ERROR, "{}", error);
}
// Set the creation datetime to 'now'.
con.execute_sql(
.unwrap();
}
Err(error) => {
- eprintln!("{}", error);
+ event!(Level::ERROR, "{}", error);
}
}