feat: emit colored log only when STDOUT is a tty

This commit is contained in:
Yujia Qiao 2022-01-11 20:59:56 +08:00 committed by Yujia Qiao
parent 67192fbb9c
commit e6dd0c8df8
3 changed files with 5 additions and 0 deletions

1
Cargo.lock generated
View File

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

View File

@ -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"] }

View File

@ -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();
}