]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Only use colorama when curses unavailable
authorMichael V. DePalatis <mike@depalatis.net>
Wed, 31 Aug 2016 11:59:18 +0000 (13:59 +0200)
committerMichael V. DePalatis <mike@depalatis.net>
Wed, 31 Aug 2016 11:59:18 +0000 (13:59 +0200)
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")
```

tornado/log.py

index c4511569d52a6ef0d97fbecbefd4a44dfe6f9b92..865f322106539952079b7596abcc112076fb23f8 100644 (file)
@@ -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 = ''