diff --git a/services/backup/Cargo.toml b/services/backup/Cargo.toml --- a/services/backup/Cargo.toml +++ b/services/backup/Cargo.toml @@ -26,7 +26,7 @@ tokio-stream = { workspace = true } tracing = { workspace = true } tracing-futures = { workspace = true, features = ["futures-03"] } -tracing-subscriber = { workspace = true, features = ["env-filter"] } +tracing-subscriber = { workspace = true, features = ["env-filter", "json"] } uuid = { workspace = true, features = ["v4"] } actix-web = { workspace = true } tracing-actix-web = { workspace = true } diff --git a/services/backup/src/constants.rs b/services/backup/src/constants.rs --- a/services/backup/src/constants.rs +++ b/services/backup/src/constants.rs @@ -14,6 +14,7 @@ // Environment variable names pub const LOG_LEVEL_ENV_VAR: &str = tracing_subscriber::filter::EnvFilter::DEFAULT_ENV; +pub const COMM_SERVICES_USE_JSON_LOGS: &str = "COMM_SERVICES_USE_JSON_LOGS"; // DynamoDB constants pub mod backup_table { diff --git a/services/backup/src/main.rs b/services/backup/src/main.rs --- a/services/backup/src/main.rs +++ b/services/backup/src/main.rs @@ -1,5 +1,7 @@ use anyhow::Result; use comm_lib::{auth::AuthService, blob::client::BlobServiceClient}; +use constants::COMM_SERVICES_USE_JSON_LOGS; +use std::env; use tracing::Level; use tracing_subscriber::EnvFilter; @@ -14,13 +16,27 @@ pub use config::CONFIG; fn configure_logging() -> Result<()> { + let use_json_logs: bool = env::var(COMM_SERVICES_USE_JSON_LOGS) + .unwrap_or("false".to_string()) + .parse() + .unwrap_or_default(); + let filter = EnvFilter::builder() .with_default_directive(Level::INFO.into()) .with_env_var(constants::LOG_LEVEL_ENV_VAR) .from_env_lossy(); - let subscriber = tracing_subscriber::fmt().with_env_filter(filter).finish(); - tracing::subscriber::set_global_default(subscriber)?; + if use_json_logs { + let subscriber = tracing_subscriber::fmt() + .json() + .with_env_filter(filter) + .finish(); + tracing::subscriber::set_global_default(subscriber)?; + } else { + let subscriber = tracing_subscriber::fmt().with_env_filter(filter).finish(); + tracing::subscriber::set_global_default(subscriber)?; + } + Ok(()) } diff --git a/services/terraform/remote/service_backup.tf b/services/terraform/remote/service_backup.tf --- a/services/terraform/remote/service_backup.tf +++ b/services/terraform/remote/service_backup.tf @@ -47,6 +47,10 @@ { name = "COMM_SERVICES_DISABLE_CSAT_VERIFICATION", value = local.is_staging ? "false" : "true" + }, + { + name = "COMM_SERVICES_USE_JSON_LOGS", + value = local.comm_services_use_json_logs } ] logConfiguration = {