diff --git a/Cargo.toml b/Cargo.toml index 466999e..624a983 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,11 +13,13 @@ actix-web = "4.10" argon2 = { version = "0.5.3", features = ["std"] } clap = { version = "4.5.37", features = ["derive"] } futures = "0.3" -getrandom = "0.3.2" -hex = "0.4.3" +getrandom = "0.3" +hex = "0.4" +log = "0.4" regex = "1.11" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" +simple_logger = "5.0.0" sqlx = { version = "0.8", features = ["runtime-tokio", "tls-native-tls", "postgres"] } toml = "0.8" url = { version = "2.5", features = ["serde"] } diff --git a/README.md b/README.md index 296ce83..1e001ad 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ services: volumes: - gorb-backend:/gorb environment: + #- RUST_LOG=debug - DATABASE_USERNAME=gorb - DATABASE_PASSWORD=gorb - DATABASE=gorb diff --git a/compose.yml b/compose.yml index 3c5d8ba..4544dea 100644 --- a/compose.yml +++ b/compose.yml @@ -15,6 +15,7 @@ services: volumes: - gorb-backend:/gorb environment: + #- RUST_LOG=debug - DATABASE_USERNAME=gorb - DATABASE_PASSWORD=gorb - DATABASE=gorb diff --git a/src/api/v1/auth/login.rs b/src/api/v1/auth/login.rs index 25ce5ae..cc6cc57 100644 --- a/src/api/v1/auth/login.rs +++ b/src/api/v1/auth/login.rs @@ -2,6 +2,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; use actix_web::{error, post, web, Error, HttpResponse}; use argon2::{PasswordHash, PasswordVerifier}; +use log::error; use regex::Regex; use serde::{Deserialize, Serialize}; use futures::StreamExt; @@ -75,14 +76,14 @@ async fn login(data: actix_web::web::Data, uuid: String, request_password: let access_token = generate_access_token(); if refresh_token.is_err() { - eprintln!("{}", refresh_token.unwrap_err()); + error!("{}", refresh_token.unwrap_err()); return HttpResponse::InternalServerError().finish() } let refresh_token = refresh_token.unwrap(); if access_token.is_err() { - eprintln!("{}", access_token.unwrap_err()); + error!("{}", access_token.unwrap_err()); return HttpResponse::InternalServerError().finish() } @@ -96,7 +97,7 @@ async fn login(data: actix_web::web::Data, uuid: String, request_password: .bind(device_name) .execute(&data.pool) .await { - eprintln!("{}", error); + error!("{}", error); return HttpResponse::InternalServerError().finish() } @@ -106,7 +107,7 @@ async fn login(data: actix_web::web::Data, uuid: String, request_password: .bind(current_time) .execute(&data.pool) .await { - eprintln!("{}", error); + error!("{}", error); return HttpResponse::InternalServerError().finish() } diff --git a/src/api/v1/auth/mod.rs b/src/api/v1/auth/mod.rs index a217d90..39408b0 100644 --- a/src/api/v1/auth/mod.rs +++ b/src/api/v1/auth/mod.rs @@ -1,6 +1,7 @@ use std::{str::FromStr, time::{SystemTime, UNIX_EPOCH}}; use actix_web::{web, HttpResponse, Scope}; +use log::error; use sqlx::Postgres; use uuid::Uuid; @@ -36,7 +37,7 @@ pub async fn check_access_token<'a>(access_token: String, pool: &'a sqlx::Pool

{ - eprintln!("{}", error); + error!("{}", error); Err(HttpResponse::InternalServerError().finish()) } } diff --git a/src/api/v1/auth/refresh.rs b/src/api/v1/auth/refresh.rs index b6af68a..1e09a8e 100644 --- a/src/api/v1/auth/refresh.rs +++ b/src/api/v1/auth/refresh.rs @@ -1,5 +1,6 @@ use std::time::{SystemTime, UNIX_EPOCH}; use actix_web::{error, post, web, Error, HttpResponse}; +use log::error; use serde::{Deserialize, Serialize}; use futures::StreamExt; @@ -41,7 +42,7 @@ pub async fn res(mut payload: web::Payload, data: web::Data) -> Result) -> Result) -> Result) -> Result { - eprintln!("{}", error); + error!("{}", error); }, } } @@ -89,7 +90,7 @@ pub async fn res(mut payload: web::Payload, data: web::Data) -> Result) -> Result) -> Result) -> Result) -> Result) -> Result { - eprintln!("{}", err_msg); + error!("{}", err_msg); HttpResponse::InternalServerError().finish() } } diff --git a/src/api/v1/auth/revoke.rs b/src/api/v1/auth/revoke.rs index e3ae752..450ac06 100644 --- a/src/api/v1/auth/revoke.rs +++ b/src/api/v1/auth/revoke.rs @@ -1,5 +1,6 @@ use actix_web::{error, post, web, Error, HttpResponse}; use argon2::{PasswordHash, PasswordVerifier}; +use log::error; use serde::{Deserialize, Serialize}; use futures::{future, StreamExt}; @@ -54,7 +55,7 @@ pub async fn res(mut payload: web::Payload, data: web::Data) -> Result) -> Result) -> Result) -> Result> = results_refresh_tokens.iter().filter(|r| r.is_err()).collect(); if !access_tokens_errors.is_empty() && !refresh_tokens_errors.is_empty() { - println!("{:?}", access_tokens_errors); - println!("{:?}", refresh_tokens_errors); + error!("{:?}", access_tokens_errors); + error!("{:?}", refresh_tokens_errors); return Ok(HttpResponse::InternalServerError().finish()) } else if !access_tokens_errors.is_empty() { - println!("{:?}", access_tokens_errors); + error!("{:?}", access_tokens_errors); return Ok(HttpResponse::InternalServerError().finish()) } else if !refresh_tokens_errors.is_empty() { - println!("{:?}", refresh_tokens_errors); + error!("{:?}", refresh_tokens_errors); return Ok(HttpResponse::InternalServerError().finish()) } diff --git a/src/api/v1/user.rs b/src/api/v1/user.rs index 25721b3..8a55288 100644 --- a/src/api/v1/user.rs +++ b/src/api/v1/user.rs @@ -1,4 +1,5 @@ use actix_web::{error, post, web, Error, HttpResponse}; +use log::error; use serde::{Deserialize, Serialize}; use futures::StreamExt; use uuid::Uuid; @@ -59,7 +60,7 @@ pub async fn res(mut payload: web::Payload, path: web::Path<(String,)>, data: we .await; if row.is_err() { - eprintln!("{}", row.unwrap_err()); + error!("{}", row.unwrap_err()); return Ok(HttpResponse::InternalServerError().finish()) } diff --git a/src/config.rs b/src/config.rs index d5bddb1..a2a6192 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,4 +1,5 @@ use crate::Error; +use log::debug; use serde::Deserialize; use sqlx::postgres::PgConnectOptions; use tokio::fs::read_to_string; @@ -22,11 +23,12 @@ pub struct Database { struct WebBuilder { url: Option, port: Option, - ssl: Option, + _ssl: Option, } impl ConfigBuilder { pub async fn load(path: String) -> Result { + debug!("loading config from: {}", path); let raw = read_to_string(path).await?; let config = toml::from_str(&raw)?; diff --git a/src/main.rs b/src/main.rs index 0a364bb..70865f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use actix_web::{App, HttpServer, web}; use argon2::Argon2; use clap::Parser; +use simple_logger::SimpleLogger; use sqlx::{PgPool, Pool, Postgres}; use std::time::SystemTime; mod config; @@ -28,6 +29,7 @@ struct Data { #[tokio::main] async fn main() -> Result<(), Error> { + SimpleLogger::new().with_level(log::LevelFilter::Info).with_colors(true).env().init().unwrap(); let args = Args::parse(); let config = ConfigBuilder::load(args.config).await?.build();