1
0
Эх сурвалжийг харах

feat: emit colored log only when STDOUT is a tty

Yujia Qiao 4 жил өмнө
parent
commit
e6dd0c8df8
3 өөрчлөгдсөн 5 нэмэгдсэн , 0 устгасан
  1. 1 0
      Cargo.lock
  2. 1 0
      Cargo.toml
  3. 3 0
      src/main.rs

+ 1 - 0
Cargo.lock

@@ -1507,6 +1507,7 @@ version = "0.3.4"
 dependencies = [
 dependencies = [
  "anyhow",
  "anyhow",
  "async-trait",
  "async-trait",
+ "atty",
  "backoff",
  "backoff",
  "base64",
  "base64",
  "bincode",
  "bincode",

+ 1 - 0
Cargo.toml

@@ -69,6 +69,7 @@ base64 = { version = "0.13", optional = true }
 notify = { version = "5.0.0-pre.13", optional = true }
 notify = { version = "5.0.0-pre.13", optional = true }
 console-subscriber = { version = "0.1", optional = true, features = ["parking_lot"] }
 console-subscriber = { version = "0.1", optional = true, features = ["parking_lot"] }
 const_format = "0.2"
 const_format = "0.2"
+atty = "0.2"
 
 
 [build-dependencies]
 [build-dependencies]
 vergen = { version = "6.0", default-features = false, features = ["build", "git", "cargo"] }
 vergen = { version = "6.0", default-features = false, features = ["build", "git", "cargo"] }

+ 3 - 0
src/main.rs

@@ -30,11 +30,14 @@ async fn main() -> Result<()> {
     }
     }
     #[cfg(not(feature = "console"))]
     #[cfg(not(feature = "console"))]
     {
     {
+        let is_atty = atty::is(atty::Stream::Stdout);
+
         let level = "info"; // if RUST_LOG not present, use `info` level
         let level = "info"; // if RUST_LOG not present, use `info` level
         tracing_subscriber::fmt()
         tracing_subscriber::fmt()
             .with_env_filter(
             .with_env_filter(
                 EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::from(level)),
                 EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::from(level)),
             )
             )
+            .with_ansi(is_atty)
             .init();
             .init();
     }
     }