Skip to content

Commit 977d76d

Browse files
authored
feat: add optional JSON log format (#46)
* feat: add optional JSON log format via LOG_FORMAT env var Set LOG_FORMAT=json to enable structured JSON logging output, useful for log aggregation services like Datadog. * style: cargo fmt
1 parent 11d0228 commit 977d76d

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bytes = "1"
4444
thiserror = "2"
4545
anyhow = "1"
4646
tracing = "0.1"
47-
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
47+
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
4848
metrics = "0.24"
4949
metrics-exporter-prometheus = "0.18"
5050

src/main.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,19 @@ use vllm_proxy_rs::{
1212
#[tokio::main]
1313
async fn main() -> anyhow::Result<()> {
1414
// Initialize tracing
15-
tracing_subscriber::fmt()
16-
.with_env_filter(
17-
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into()),
18-
)
19-
.init();
15+
let env_filter =
16+
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into());
17+
let json_logs = std::env::var("LOG_FORMAT")
18+
.map(|v| v.eq_ignore_ascii_case("json"))
19+
.unwrap_or(false);
20+
if json_logs {
21+
tracing_subscriber::fmt()
22+
.json()
23+
.with_env_filter(env_filter)
24+
.init();
25+
} else {
26+
tracing_subscriber::fmt().with_env_filter(env_filter).init();
27+
}
2028

2129
// Load config
2230
let config = config::Config::from_env()?;

0 commit comments

Comments
 (0)