- update: logging system to only show logs from the app and not any 3rd party dependencies
This commit is contained in:
@@ -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
19
utils/src/logging.rs
Normal 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");
|
||||
}
|
||||
Reference in New Issue
Block a user