Drakulix / simplelog.rs

Simple Logging Facility for Rust
https://docs.rs/simplelog/
Apache License 2.0
443 stars 73 forks source link

TermLogger emits colors when stdout is not a TTY #108

Open kartva opened 2 years ago

kartva commented 2 years ago
use simplelog::{TermLogger, Config};
use log::*;

fn main() {
    TermLogger::init(LevelFilter::Debug, Config::default(), simplelog::TerminalMode::Stdout, simplelog::ColorChoice::Auto).unwrap();
    log::info!("hello");
}

running

cargo run > test.txt

results in ANSI output being written to test.txt.

kartva commented 2 years ago

This appears to be an issue in termcolor library that simplelog uses.

kartva commented 2 years ago

termcolor explicitly states that it makes no effort to check whether the stream it's printing to is a TTY or not. It recommends atty for the same. supports_color is a wrapper over atty that also checks the NO_COLOR env variable.