mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-11 14:35:13 +00:00
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
This commit is contained in:
@@ -45,11 +45,26 @@ struct Args {
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
// Initialize tracing
|
// Initialize tracing with centralized logging support
|
||||||
tracing_subscriber::fmt()
|
let log_format = std::env::var("LOG_FORMAT").unwrap_or_else(|_| "compact".to_string());
|
||||||
.with_target(false)
|
let log_json = std::env::var("LOG_JSON").unwrap_or_else(|_| "false".to_string()) == "true";
|
||||||
.compact()
|
|
||||||
.init();
|
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();
|
dotenv::dotenv().ok();
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|||||||
Reference in New Issue
Block a user