From 303159ef309e7c65f03a09ecbd8987abe08c8b3f Mon Sep 17 00:00:00 2001 From: Walter Oggioni Date: Fri, 4 Jul 2025 12:55:08 +0800 Subject: [PATCH] another commit --- .env | 1 + Cargo.toml | 1 - src/main.rs | 18 ++++++++++-------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.env b/.env index 5e88d0d..5a9fb5d 100644 --- a/.env +++ b/.env @@ -3,3 +3,4 @@ INTRASYS_PORT=8080 PGUSER=postgres PGHOST=127.0.0.1 PGPASSWORD=password +INTRASYS_LOG=trace diff --git a/Cargo.toml b/Cargo.toml index 001f9a2..a28da6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ serde_json = "1.0" sqlx = { version = "0.8", features = ["postgres", "runtime-tokio", "chrono", "bigdecimal", "derive"] } thiserror = "2.0" uuid = { version = "1.17", features = ["v4"] } -# validator = { version = "0.20", features = ["derive"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } dotenv = "0.15" diff --git a/src/main.rs b/src/main.rs index 8c20bd4..e0f9759 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,24 +5,26 @@ use axum::{ routing::{get, post}, }; use dotenv::dotenv; -use tracing::{Level, info}; -use tracing_subscriber::FmtSubscriber; +use tracing::info; +use tracing_subscriber::layer::SubscriberExt; mod db; mod errors; mod handlers; mod models; -#[tokio::main] +#[tokio::main(flavor = "current_thread")] async fn main() { //Parse .env file and add the environmental variables configured there dotenv().ok(); - let subscriber = FmtSubscriber::builder() - .with_max_level(Level::TRACE) - .finish(); + let subscriber = tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("INTRASYS_LOG").unwrap_or_else(|_| "info".into()), + )) + .with(tracing_subscriber::fmt::layer()); tracing::subscriber::set_global_default(subscriber) - .expect("Setting default tracing subscriber failed"); + .expect("Failed to set the global tracing subscriber"); let pool = db::create_pool().await.expect("Failed to create pool"); @@ -41,7 +43,7 @@ async fn main() { // Run the server let host = env::var("INTRASYS_HOST").unwrap_or(String::from("127.0.0.1")); let port = env::var("INTRASYS_PORT").unwrap_or(String::from("8080")); - let listener = tokio::net::TcpListener::bind(format!("{}:{}", host, port)) + let listener = tokio::net::TcpListener::bind(format!("{host}:{port}")) .await .unwrap(); info!("listening on {}", listener.local_addr().unwrap());