- update: logging system to only show logs from the app and not any 3rd party dependencies
This commit is contained in:
@@ -6,7 +6,9 @@ use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
use tracing::{info, Level};
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use utils::consul_registration;
|
||||
use utils::logging;
|
||||
use utils::service_discovery::{get_kube_service_endpoints_by_dns};
|
||||
|
||||
mod axum_gateway;
|
||||
@@ -14,12 +16,8 @@ mod axum_gateway;
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
dotenv().ok();
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(
|
||||
Level::from_str(&env::var("LOG_LEVEL").unwrap_or_else(|_| "info".to_string()))
|
||||
.unwrap_or_else(|_| Level::INFO),
|
||||
)
|
||||
.init();
|
||||
let app_name = env!("CARGO_PKG_NAME");
|
||||
logging::setup_logging(app_name);
|
||||
|
||||
// Set the gRPC server address
|
||||
let addr = env::var("LISTEN_ADDR").unwrap_or_else(|_| "0.0.0.0".to_string());
|
||||
|
||||
@@ -15,7 +15,7 @@ argon2 = "0.5.3"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
dotenv = "0.15"
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "chrono"] }
|
||||
tracing-subscriber = { version = "0.3.19", features = ["env-filter", "chrono"] }
|
||||
prost = "0.13.4"
|
||||
prost-types = "0.13.3"
|
||||
chrono = { version = "0.4.38", features = ["serde"] }
|
||||
|
||||
@@ -4,14 +4,12 @@ use auth_service::database_client::DatabaseClientTrait;
|
||||
use auth_service::grpc::MyAuthService;
|
||||
use auth_service::session::session_service_client::SessionServiceClient;
|
||||
use dotenv::dotenv;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use tonic::transport::Server;
|
||||
use tracing::{debug, info, Level};
|
||||
use utils::consul_registration;
|
||||
use utils::multi_service_load_balancer::{LoadBalancingStrategy, MultiServiceLoadBalancer};
|
||||
use tracing::info;
|
||||
use tracing_subscriber::{fmt, EnvFilter};
|
||||
use utils::logging;
|
||||
use utils::service_discovery::{get_kube_service_endpoints_by_dns};
|
||||
|
||||
#[tokio::main]
|
||||
@@ -19,13 +17,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Load environment variables from .env
|
||||
dotenv().ok();
|
||||
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(
|
||||
Level::from_str(&env::var("LOG_LEVEL").unwrap_or_else(|_| "info".to_string()))
|
||||
.unwrap_or_else(|_| Level::INFO),
|
||||
)
|
||||
.init();
|
||||
|
||||
let app_name = env!("CARGO_PKG_NAME");
|
||||
logging::setup_logging(app_name);
|
||||
|
||||
// Set the gRPC server address
|
||||
let addr = env::var("LISTEN_ADDR").unwrap_or_else(|_| "0.0.0.0".to_string());
|
||||
let port = env::var("SERVICE_PORT").unwrap_or_else(|_| "50051".to_string());
|
||||
@@ -45,7 +39,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let (mut health_reporter, health_service) = tonic_health::server::health_reporter();
|
||||
health_reporter.set_serving::<AuthServiceServer<MyAuthService>>().await;
|
||||
|
||||
println!("Authentication Service running on {}", addr);
|
||||
info!("Authentication Service running on {}", addr);
|
||||
|
||||
// Start the gRPC server
|
||||
tokio::spawn(
|
||||
|
||||
@@ -9,7 +9,7 @@ dotenv = "0.15"
|
||||
tokio = { version = "1.41.1", features = ["full"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = "0.3.18"
|
||||
tracing-subscriber = { version = "0.3.19", features = ["env-filter", "chrono"] }
|
||||
tonic = "0.12.3"
|
||||
prost = "0.13.4"
|
||||
warp = "0.3.7"
|
||||
|
||||
@@ -12,17 +12,15 @@ use std::env;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use tracing::Level;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use utils::logging;
|
||||
use utils::service_discovery::{get_kube_service_endpoints_by_dns};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
dotenv().ok();
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(
|
||||
Level::from_str(&env::var("LOG_LEVEL").unwrap_or_else(|_| "info".to_string()))
|
||||
.unwrap_or_else(|_| Level::INFO),
|
||||
)
|
||||
.init();
|
||||
let app_name = env!("CARGO_PKG_NAME");
|
||||
logging::setup_logging(app_name);
|
||||
|
||||
// Set the gRPC server address
|
||||
let addr = env::var("LISTEN_ADDR").unwrap_or_else(|_| "0.0.0.0".to_string());
|
||||
|
||||
@@ -15,7 +15,7 @@ chrono = { version = "0.4.39", features = ["serde"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
dotenv = "0.15"
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "chrono"] }
|
||||
tracing-subscriber = { version = "0.3.19", features = ["env-filter", "chrono"] }
|
||||
prost = "0.13.3"
|
||||
serde_json = "1.0.133"
|
||||
async-trait = "0.1.83"
|
||||
|
||||
@@ -11,17 +11,15 @@ use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
use tonic::transport::Server;
|
||||
use tracing::{info, Level};
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use utils::logging;
|
||||
use utils::redis_cache::RedisCache;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
dotenv().ok();
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(
|
||||
Level::from_str(&env::var("LOG_LEVEL").unwrap_or_else(|_| "info".to_string()))
|
||||
.unwrap_or_else(|_| Level::INFO),
|
||||
)
|
||||
.init();
|
||||
let app_name = env!("CARGO_PKG_NAME");
|
||||
logging::setup_logging(app_name);
|
||||
|
||||
let addr = env::var("LISTEN_ADDR").unwrap_or_else(|_| "0.0.0.0".to_string());
|
||||
let port = env::var("SERVICE_PORT").unwrap_or_else(|_| "50052".to_string());
|
||||
|
||||
@@ -13,7 +13,7 @@ tokio = { version = "1.41.1", features = ["full"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
bytes = { version = "1.8.0", features = ["std", "serde"] }
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = "0.3.18"
|
||||
tracing-subscriber = { version = "0.3.19", features = ["env-filter", "chrono"] }
|
||||
bincode = { version = "2.0.0", features = ["derive", "serde"] }
|
||||
thiserror = "2.0.3"
|
||||
lazy_static = "1.5.0"
|
||||
|
||||
@@ -20,7 +20,8 @@ use tokio::sync::{Mutex, Semaphore};
|
||||
use tokio::{select, signal};
|
||||
use tracing::Level;
|
||||
use tracing::{debug, error, info, warn};
|
||||
use utils::consul_registration;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use utils::{consul_registration, logging};
|
||||
use utils::service_discovery::{get_kube_service_endpoints_by_dns};
|
||||
use warp::Filter;
|
||||
|
||||
@@ -58,12 +59,8 @@ const MAX_CONCURRENT_CONNECTIONS: usize = 100;
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
dotenv().ok();
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(
|
||||
Level::from_str(&env::var("LOG_LEVEL").unwrap_or_else(|_| "info".to_string()))
|
||||
.unwrap_or_else(|_| Level::INFO),
|
||||
)
|
||||
.init();
|
||||
let app_name = env!("CARGO_PKG_NAME");
|
||||
logging::setup_logging(app_name);
|
||||
|
||||
// Set the gRPC server address
|
||||
let addr = env::var("LISTEN_ADDR").unwrap_or_else(|_| "0.0.0.0".to_string());
|
||||
|
||||
@@ -9,7 +9,7 @@ dotenv = "0.15"
|
||||
tokio = { version = "1.41.1", features = ["full"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = "0.3.18"
|
||||
tracing-subscriber = { version = "0.3.19", features = ["env-filter", "chrono"] }
|
||||
tonic = "0.12.3"
|
||||
prost = "0.13.4"
|
||||
warp = "0.3.7"
|
||||
|
||||
@@ -10,7 +10,8 @@ use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
use tonic::transport::Server;
|
||||
use tracing::Level;
|
||||
use utils::consul_registration;
|
||||
use tracing_subscriber::{fmt, EnvFilter};
|
||||
use utils::{consul_registration, logging};
|
||||
use utils::redis_cache::RedisCache;
|
||||
|
||||
pub mod common {
|
||||
@@ -24,12 +25,8 @@ pub mod api {
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
dotenv().ok();
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(
|
||||
Level::from_str(&env::var("LOG_LEVEL").unwrap_or_else(|_| "info".to_string()))
|
||||
.unwrap_or_else(|_| Level::INFO),
|
||||
)
|
||||
.init();
|
||||
let app_name = env!("CARGO_PKG_NAME");
|
||||
logging::setup_logging(app_name);
|
||||
|
||||
// Set the gRPC server address
|
||||
let addr = env::var("LISTEN_ADDR").unwrap_or_else(|_| "0.0.0.0".to_string());
|
||||
|
||||
@@ -19,3 +19,4 @@ hickory-resolver = "0.24.4"
|
||||
rand = "0.8.5"
|
||||
kube = { version = "0.99.0", features = ["derive"] }
|
||||
k8s-openapi = { version = "0.24.0", features = ["v1_32"] }
|
||||
tracing-subscriber = { version = "0.3.19", features = ["env-filter", "chrono"] }
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
@@ -9,7 +9,7 @@ dotenv = "0.15"
|
||||
tokio = { version = "1.41.1", features = ["full"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = "0.3.18"
|
||||
tracing-subscriber = { version = "0.3.19", features = ["env-filter", "chrono"] }
|
||||
tonic = "0.12.3"
|
||||
prost = "0.13.4"
|
||||
warp = "0.3.7"
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
use dotenv::dotenv;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::str::FromStr;
|
||||
use tracing::{debug, Level};
|
||||
use utils::consul_registration;
|
||||
use utils::{consul_registration, logging};
|
||||
use utils::service_discovery::{get_kube_service_endpoints_by_dns, get_service_endpoints_by_dns};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
dotenv().ok();
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(
|
||||
Level::from_str(&env::var("LOG_LEVEL").unwrap_or_else(|_| "info".to_string()))
|
||||
.unwrap_or_else(|_| Level::INFO),
|
||||
)
|
||||
.init();
|
||||
let app_name = env!("CARGO_PKG_NAME");
|
||||
logging::setup_logging(app_name);
|
||||
|
||||
// Set the gRPC server address
|
||||
let addr = env::var("LISTEN_ADDR").unwrap_or_else(|_| "0.0.0.0".to_string());
|
||||
|
||||
Reference in New Issue
Block a user