PyCharm logging output colours

后端 未结 7 669
情话喂你
情话喂你 2020-12-24 11:05

I\'m using PyCharm to develop a GAE app in Mac OS X. Is there any way to display colours in the run console of PyCharm?

I\'ve set a handler to output colours in ansi

7条回答
  •  抹茶落季
    2020-12-24 11:32

    Sept. 2019: PyCharm Community 2019.1

    PyCharm colored all the logs including info/debug in red.

    Th upshot is: it is not a PyCharm problem, this is how the default logging is configured. Everything written to sys.stderr is colored red by PyCharm. When using StreamHandler() without arguments, the default stream is sys.stderr.

    For getting non-colored logs back, specify logging.StreamHandler(stream=sys.stdout) in basic config like this:

    logging.basicConfig(
        level=logging.DEBUG,
        format='[%(levelname)8s]:  %(message)s',
        handlers=[
            logging.FileHandler(f'{os.path.basename(__file__)}.log'),
            logging.StreamHandler(sys.stdout),
        ])
    

    or be more verbose:

    logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
    

    This fixed my red PyCharm logs.

提交回复
热议问题