Open kartva opened 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.
test.txt
This appears to be an issue in termcolor library that simplelog uses.
termcolor
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.
atty
supports_color
NO_COLOR
running
results in ANSI output being written to
test.txt
.