Drakulix/simplelog.rs

TermLogger emits colors when stdout is not a TTY

kartva opened this issue · 2 comments

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.

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

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.