simplelog.rs
simplelog.rs copied to clipboard
TermLogger emits colors when stdout is not a TTY
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.