[update] added JSON logging support with tracing-subscriber for production, updated dependencies in Cargo.toml and Cargo.lock

This commit is contained in:
2025-08-06 14:02:33 +02:00
parent 0ce916c654
commit 3a5b0d8f4b
3 changed files with 17 additions and 1 deletions

View File

@@ -2279,6 +2279,16 @@ dependencies = [
"tracing-core", "tracing-core",
] ]
[[package]]
name = "tracing-serde"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "704b1aeb7be0d0a84fc9828cae51dab5970fee5088f83d1dd7ee6f6246fc6ff1"
dependencies = [
"serde",
"tracing-core",
]
[[package]] [[package]]
name = "tracing-subscriber" name = "tracing-subscriber"
version = "0.3.19" version = "0.3.19"
@@ -2289,12 +2299,15 @@ dependencies = [
"nu-ansi-term", "nu-ansi-term",
"once_cell", "once_cell",
"regex", "regex",
"serde",
"serde_json",
"sharded-slab", "sharded-slab",
"smallvec", "smallvec",
"thread_local", "thread_local",
"tracing", "tracing",
"tracing-core", "tracing-core",
"tracing-log", "tracing-log",
"tracing-serde",
] ]
[[package]] [[package]]

View File

@@ -12,7 +12,7 @@ serde_json = "1.0"
sqlx = { version = "0.8", features = ["runtime-tokio", "tls-native-tls", "sqlite", "macros", "migrate", "chrono", "json"] } sqlx = { version = "0.8", features = ["runtime-tokio", "tls-native-tls", "sqlite", "macros", "migrate", "chrono", "json"] }
dotenv = "0.15" dotenv = "0.15"
tracing = "0.1" tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
toml = "0.9.5" toml = "0.9.5"
[dev-dependencies] [dev-dependencies]

View File

@@ -11,12 +11,15 @@ use axum::routing::get;
use tokio::signal; use tokio::signal;
use tracing::{info}; use tracing::{info};
use tracing_subscriber; use tracing_subscriber;
use tracing_subscriber::EnvFilter;
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
tracing_subscriber::fmt() tracing_subscriber::fmt()
.with_target(false) .with_target(false)
.compact() .compact()
.with_env_filter(EnvFilter::from_default_env())
.json() // For production
.init(); .init();
let app_settings = AppSettings::get_app_settings(); let app_settings = AppSettings::get_app_settings();