Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TermLogger emits colors when stdout is not a TTY #108

Open
kartva opened this issue Jul 21, 2022 · 2 comments
Open

TermLogger emits colors when stdout is not a TTY #108

kartva opened this issue Jul 21, 2022 · 2 comments

Comments

@kartva
Copy link
Contributor

kartva commented Jul 21, 2022

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
Copy link
Contributor Author

kartva commented Jul 21, 2022

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

@kartva
Copy link
Contributor Author

kartva commented Jul 21, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant