Closed at-wat closed 4 years ago
How about the use case of redirecting the output to a file but still wanting to have colorization?
Maybe better to read a environment variable like ROSCONSOLE_COLOR_ALWAY
and force using text color if set.
Is it better to keep always colored by default?
For your use case checking for an environment variable like NO_COLOR
(https://no-color.org/) might be the best option. If it is present skip all colorization.
Supporting NO_COLOR
sounds good to me. I'm going to add a support for NO_COLOR
environment variable.
By the way, rospy.log*()
seems checking isatty()
and doesn't use ANSI color when the output is not a terminal.
https://github.com/ros/ros_comm/blob/c6ad71e7105f151d912c8c0db3bd18caad771e89/tools/rosgraph/src/rosgraph/roslogging.py#L296
NO_COLOR environment variable version: https://github.com/ros/rosconsole/pull/46
ANSI escape sequence causes corrupted text if the output is not a terminal. (e.g. redirect to file, docker logs) Check output file descriptor is a terminal and skip applying text color if not.