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
PyCharm 2019.1.1 (Windows 10, 1709) - runned snippet as is - works correctly.
Bug: setFormatter - does not work.
Fix: make change in line 67 and get rid on line 70-71 (unformatted handler adding).
self.stream.write(record.msg + "\n", color)
to
self.stream.write(self.format(record) + "\n", color)
Line 70-71 can be moved under manual file run construction for save test ability:
if __name__ == "__main__":
logging.getLogger().setLevel(logging.DEBUG)
logging.getLogger().addHandler(ColorHandler())
logging.debug("Some debugging output")
logging.info("Some info output")
logging.error("Some error output")
logging.warning("Some warning output")
Compared it with standard StreamHandler:
import logging
import logging_colored
log_format = logging.Formatter("[%(threadName)-15.15s] [%(levelname)-5.5s] %(message)s")
logger = logging.getLogger('Main')
logger.setLevel(logging.DEBUG)
console = logging.StreamHandler()
console.setFormatter(log_format)
logger.addHandler(console)
console = logging_colored.ColorHandler()
console.setFormatter(log_format)
logger.addHandler(console)
...