- update: logging system to only show logs from the app and not any 3rd party dependencies

This commit is contained in:
2025-03-19 02:13:02 -04:00
parent 03cef8e526
commit 98b8d412e7
16 changed files with 57 additions and 61 deletions

View File

@@ -4,3 +4,4 @@ pub mod redis_cache;
pub mod service_discovery;
pub mod signal_handler;
pub mod multi_service_load_balancer;
pub mod logging;

19
utils/src/logging.rs Normal file
View File

@@ -0,0 +1,19 @@
use std::env;
use tracing::{debug, error, info, trace, warn};
use tracing_subscriber::EnvFilter;
pub fn setup_logging(app_name: &str) {
let log_level = env::var("LOG_LEVEL").unwrap_or_else(|_| "info".to_string());
let filter = EnvFilter::try_new(format!("{app_name}={log_level},utils={log_level}"))
.unwrap_or_else(|_| EnvFilter::new(format!("{app_name}=info,utils=info")));
tracing_subscriber::fmt()
.with_env_filter(filter)
.init();
error!("Error messages enabled");
warn!("Warning messages enabled");
info!("Info messages enabled");
debug!("Debug messages enabled");
trace!("Trace messages enabled");
}