colorlog introduces "[1m[0m"-like entries in logs running on argo workflows
thomasaarholt opened this issue · comments
I introduced colorlog to our workflow at my company. Locally, it looks fantastic, but when we run it on argo (a kubernetes workflow tool), then the log gets piped into a very basic text viewer which lacks color. In this case, the following output looks like the "after adding colorlog" case below:
Before adding colorlog:
11-11 13:15:35 INFO Initialize log
After adding colorlog:
[1m[32m11-11 13:25:13 INFO Initialize log
Is there any way to avoid this, other than somehow detecting that we are running "in the cloud", and not using color? I saw #81 and it seems related?
There are a few things you can do, starting with the least complex:
- Set the
NO_COLOR
environment variable (https://no-color.org/). - Pass
stream=sys.stderr
tocolorlog.formatter.ColoredFormatter
. This will enable TTY detection and should disable colors when not running in an interactive terminal. - Have separate logging configuration for running in the cloud or for running localy, and only use
colorlog
for the local configuration. There are a number of ways to do this that the stdliblogging
documentation covers in more detail.
Thank you! I went with your second option. I had to also add a check to see if the python instance was in a jupyter notebook, since that apparently didn't count as an interactive terminal.