15

I'm using VSCode for coding Python. The problem is VSCode prints any output (Errors, Warning and ...) in the same format and color.

Is there any extension or tools to manage it? for example like PyCharm print errors with Red color, warning with yellow and so on?

Zoe stands with Ukraine
  • 25,310
  • 18
  • 114
  • 149
Sina
  • 492
  • 5
  • 18

3 Answers3

4

That's not a problem with vscode, but general thing with bash/powershell/cmd (kind reminder that the console that vscode uses, is driven by powershell/bash).

I think I managed to find a fine solution/mitigation for your problem. I found this answer which gave nice results.

enter image description here TBH I don't like this IPython look. Never did. After some research I came up with this improved code

import sys
from IPython.core.ultratb import ColorTB

sys.excepthook = ColorTB()

Which colored well for me on Windows: enter image description here But adding this code each time will be... Very annoying. We should find a way to make it run on any .py on vscode.

I found a way to make any Python file run some line of code before running any script. Go to your python PythonXY\Lib\site-packages where XY is your python version. Add file named exactly sitecustomize.py, and add our improved script.

Test it by printing non-existent variable print(a) and you should see color :)

barshopen
  • 946
  • 1
  • 13
  • 23
2

Check out this library. This will enable you to use formatted output in the terminal.

Shayan Shafiq
  • 1
  • 5
  • 17
  • 24
Saurabh Jain
  • 1,448
  • 1
  • 19
  • 29
0

There is no such extension in the VS Code. You have to use Python libraries to do so. For showing different logs in different colors use pip install coloredlogs.

Example from documenation:

import coloredlogs, logging
logger = logging.getLogger(__name__)
coloredlogs.install(level='DEBUG')

logger.debug("this is a debugging message")
logger.info("this is an informational message")
logger.warning("this is a warning message")
logger.error("this is an error message")
logger.critical("this is a critical message")

If you're a Windows user and if the above doesn't work then you've to use an additional dependency pip install colorama.

Mrinal Roy
  • 914
  • 7
  • 12