-
Notifications
You must be signed in to change notification settings - Fork 741
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
Only colorize output when outputting to a TTY #1160
Comments
Rustc does this with an environment variable, RUSTC_LOG_COLOR. I would prefer not to do this in tracing itself so the variable can be customized. Tracing could add an API setting the variable but at that point you may as well do it yourself in the application. |
An env variable can be implemented in user code with the current APIs in We could add support for a default env variable, though, if that's something people want --- but that part should be pretty easy to implement on top of the current API. It's automatically detecting whether the output is a TTY that's significantly more challenging, especially with the current design of |
I would request that with_ansi be renamed to with_colors. Was confused as to how to disable colors and ansi was never the word I looked for in docs |
We could rename it to It does also control other formatting, though, such as bold and italic.. |
@zojw thank you for that mention with an example how to achieve the usually desired behavior. |
It might be reasonable to use the supports-color crate for this. However, there is a trade-off that would have to be made
|
Feature Request
Motivation
Tracing's default output is colorized. But when a program is not connected to a terminal, for instance because its output is redirected to a file or another program like
grep
, this is undesirable because ANSI characters pollute the output.Proposal
By default, tracing should only colorize output when its output stream is a TTY, similarly to how
cargo
works. When the output does not target a terminal, ANSI characters should be omitted.It's probably desirable to support an environment variable, e.g.
RUST_LOG_COLOR
, that supports the valuesauto
(default),never
, andalways
(similar tocargo --color=...
) so that users may override the automatic behavior as desired. This is especially useful when, for instance, redirecting the program's output like|& less
so that colorized output can still be viewed in the pager.The text was updated successfully, but these errors were encountered: