From: Michael V. DePalatis Date: Wed, 31 Aug 2016 11:59:18 +0000 (+0200) Subject: Only use colorama when curses unavailable X-Git-Tag: v4.5.0~22^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43413a2cb962e59d8f528aa568edcd5ea59f71d4;p=thirdparty%2Ftornado.git Only use colorama when curses unavailable This also uses dimmer colors for Windows. This can be tested with the following script: ```python import logging from tornado.log import enable_pretty_logging logger = logging.getLogger() enable_pretty_logging() logger.setLevel(logging.DEBUG) logger.info("INFO") logger.warning("WARNING") logger.debug("DEBUG") logger.error("ERROR") print("normal") ``` --- diff --git a/tornado/log.py b/tornado/log.py index c4511569d..865f32210 100644 --- a/tornado/log.py +++ b/tornado/log.py @@ -119,7 +119,7 @@ class LogFormatter(logging.Formatter): self._fmt = fmt self._colors = {} - if color and _stderr_supports_color() and not colorama: + if color and _stderr_supports_color() and curses is not None: # The curses module has some str/bytes confusion in # python3. Until version 3.2.3, most methods return # bytes, but only accept strings. In addition, we want to @@ -135,9 +135,9 @@ class LogFormatter(logging.Formatter): for levelno, code in colors.items(): self._colors[levelno] = unicode_type(curses.tparm(fg_color, code), "ascii") self._normal = unicode_type(curses.tigetstr("sgr0"), "ascii") - elif colorama: + elif colorama is not None: for levelno, code in colors.items(): - self._colors[levelno] = '\033[3{}m'.format(code) + self._colors[levelno] = '\033[2;3%dm' % code self._normal = '\033[0m' else: self._normal = ''