feat: add flag to CLI to disable colour coding of console output (#4033)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Alessandro Mazza
2023-08-14 11:25:44 +02:00
committed by GitHub
parent 1d40f7197e
commit 4ff8bca977
2 changed files with 44 additions and 5 deletions

View File

@ -43,13 +43,14 @@ pub fn init(layers: Vec<BoxedLayer<Registry>>) {
///
/// Colors can be disabled with `RUST_LOG_STYLE=never`, and event targets can be displayed with
/// `RUST_LOG_TARGET=1`.
pub fn stdout<S>(default_directive: impl Into<Directive>) -> BoxedLayer<S>
pub fn stdout<S>(default_directive: impl Into<Directive>, color: &str) -> BoxedLayer<S>
where
S: Subscriber,
for<'a> S: LookupSpan<'a>,
{
// TODO: Auto-detect
let with_ansi = std::env::var("RUST_LOG_STYLE").map(|val| val != "never").unwrap_or(true);
let with_ansi =
std::env::var("RUST_LOG_STYLE").map(|val| val != "never").unwrap_or(color != "never");
let with_target = std::env::var("RUST_LOG_TARGET").map(|val| val != "0").unwrap_or(true);
let filter =