From be6b6856fab8da5fdba80022b0eb4a9b8d73c92b Mon Sep 17 00:00:00 2001 From: nutcas3 Date: Sat, 25 Apr 2026 05:54:13 +0300 Subject: [PATCH] feat: Add configurable logging with JSON and pretty format support to packet gateway - Add LOG_FORMAT environment variable with compact/pretty format options - Add LOG_JSON environment variable for JSON output toggle - Add EnvFilter with INFO level default to tracing subscriber - Enable target display in log output - Add conditional initialization for JSON, pretty, and compact log formats - Add startup log message showing active logging configuration --- apps/packet-gateway/src/main.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/apps/packet-gateway/src/main.rs b/apps/packet-gateway/src/main.rs index 05c5186..f7fd5a5 100644 --- a/apps/packet-gateway/src/main.rs +++ b/apps/packet-gateway/src/main.rs @@ -45,11 +45,26 @@ struct Args { #[tokio::main] async fn main() -> Result<()> { - // Initialize tracing - tracing_subscriber::fmt() - .with_target(false) - .compact() - .init(); + // Initialize tracing with centralized logging support + let log_format = std::env::var("LOG_FORMAT").unwrap_or_else(|_| "compact".to_string()); + let log_json = std::env::var("LOG_JSON").unwrap_or_else(|_| "false".to_string()) == "true"; + + let subscriber = tracing_subscriber::fmt() + .with_target(true) + .with_env_filter( + tracing_subscriber::EnvFilter::from_default_env() + .add_directive(tracing::LevelFilter::INFO.into()) + ); + + if log_json { + subscriber.json().init(); + } else if log_format == "pretty" { + subscriber.pretty().init(); + } else { + subscriber.compact().init(); + } + + info!("Packet gateway logging initialized (format: {}, json: {})", log_format, log_json); dotenv::dotenv().ok(); let args = Args::parse();