Преглед на файлове

feat: emit colored log only when STDOUT is a tty

Yujia Qiao преди 4 години
родител
ревизия
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 = [
  "anyhow",
  "async-trait",
+ "atty",
  "backoff",
  "base64",
  "bincode",

+ 1 - 0
Cargo.toml

@@ -69,6 +69,7 @@ base64 = { version = "0.13", optional = true }
 notify = { version = "5.0.0-pre.13", optional = true }
 console-subscriber = { version = "0.1", optional = true, features = ["parking_lot"] }
 const_format = "0.2"
+atty = "0.2"
 
 [build-dependencies]
 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"))]
     {
+        let is_atty = atty::is(atty::Stream::Stdout);
+
         let level = "info"; // if RUST_LOG not present, use `info` level
         tracing_subscriber::fmt()
             .with_env_filter(
                 EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::from(level)),
             )
+            .with_ansi(is_atty)
             .init();
     }