浏览代码

feat(fortuna): json format on prod (#2806)

Amin Moghaddam 5 月之前
父节点
当前提交
d5d48bcec6
共有 3 个文件被更改,包括 27 次插入13 次删除
  1. 14 1
      apps/fortuna/Cargo.lock
  2. 2 2
      apps/fortuna/Cargo.toml
  3. 11 10
      apps/fortuna/src/main.rs

+ 14 - 1
apps/fortuna/Cargo.lock

@@ -1647,7 +1647,7 @@ dependencies = [
 
 
 [[package]]
 [[package]]
 name = "fortuna"
 name = "fortuna"
-version = "7.6.4"
+version = "7.6.5"
 dependencies = [
 dependencies = [
  "anyhow",
  "anyhow",
  "axum",
  "axum",
@@ -4750,6 +4750,16 @@ dependencies = [
  "tracing-core",
  "tracing-core",
 ]
 ]
 
 
+[[package]]
+name = "tracing-serde"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1"
+dependencies = [
+ "serde",
+ "tracing-core",
+]
+
 [[package]]
 [[package]]
 name = "tracing-subscriber"
 name = "tracing-subscriber"
 version = "0.3.17"
 version = "0.3.17"
@@ -4760,12 +4770,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]]

+ 2 - 2
apps/fortuna/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 [package]
 name = "fortuna"
 name = "fortuna"
-version = "7.6.4"
+version = "7.6.5"
 edition = "2021"
 edition = "2021"
 
 
 [lib]
 [lib]
@@ -32,7 +32,7 @@ sha3 = "0.10.8"
 tokio = { version = "1.33.0", features = ["full"] }
 tokio = { version = "1.33.0", features = ["full"] }
 tower-http = { version = "0.4.0", features = ["cors"] }
 tower-http = { version = "0.4.0", features = ["cors"] }
 tracing = { version = "0.1.37", features = ["log"] }
 tracing = { version = "0.1.37", features = ["log"] }
-tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
+tracing-subscriber = { version = "0.3.17", features = ["env-filter", "json"] }
 utoipa = { version = "3.4.0", features = ["axum_extras"] }
 utoipa = { version = "3.4.0", features = ["axum_extras"] }
 utoipa-swagger-ui = { version = "3.1.4", features = ["axum"] }
 utoipa-swagger-ui = { version = "3.1.4", features = ["axum"] }
 once_cell = "1.18.0"
 once_cell = "1.18.0"

+ 11 - 10
apps/fortuna/src/main.rs

@@ -17,16 +17,17 @@ use {
 #[tracing::instrument]
 #[tracing::instrument]
 async fn main() -> Result<()> {
 async fn main() -> Result<()> {
     // Initialize a Tracing Subscriber
     // Initialize a Tracing Subscriber
-    tracing::subscriber::set_global_default(
-        tracing_subscriber::fmt()
-            .compact()
-            .with_file(false)
-            .with_line_number(true)
-            .with_thread_ids(true)
-            .with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
-            .with_ansi(std::io::stderr().is_terminal())
-            .finish(),
-    )?;
+    let fmt_builder = tracing_subscriber::fmt()
+        .with_file(false)
+        .with_line_number(true)
+        .with_thread_ids(true)
+        .with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
+        .with_ansi(std::io::stderr().is_terminal());
+    if std::io::stderr().is_terminal() {
+        tracing::subscriber::set_global_default(fmt_builder.compact().finish())?;
+    } else {
+        tracing::subscriber::set_global_default(fmt_builder.json().finish())?;
+    }
 
 
     match config::Options::parse() {
     match config::Options::parse() {
         config::Options::GetRequest(opts) => command::get_request(&opts).await,
         config::Options::GetRequest(opts) => command::get_request(&opts).await,