python-coloredlogs
python-coloredlogs copied to clipboard
coloredlogs output is only red in PyCharm
Hello, since a few weeks, coloredlogs doesn't display colors properly anymore in the PyCharm console. It did before! If I run the same code from terminal, everything works fine. I can see only red text for logging output. print() statements are usually displayed with white font. Anybody else having this issue?
I have the same issue in visual studio code I'm not conviced that it's coloredlogs fault though since when I go back to version 9.0 it still only displays in red
In Pycharm, you need to enable Emulate terminal in output console
in your run configuration options.
Source: https://stackoverflow.com/a/45534743
same issue, however, if you log with ansi color, the message is displaying color correctly sample code:
#after coloredlogs.install
logging.warning("\033[38;2;255;178;4mtest")
after this, all the logging becomes yellow, it seems like coloredlogs is not printing any effective ANSI escapes at all
UPDATE & WORKAROUND
the root cause of this problem is the sys.stderr.isatty()
which is used in humanfriendly (to check if the stream is connected to a terminal) returns False in python console, which makes coloredlogs to disable ANSI escape sequences during initialization, a patch is uploaded #97 so you can use isatty=True
to force enable ANSI escape sequences