diff --git a/qutebrowser/utils/log.py b/qutebrowser/utils/log.py index 132084035..d4a86348c 100644 --- a/qutebrowser/utils/log.py +++ b/qutebrowser/utils/log.py @@ -26,11 +26,17 @@ from collections import deque from PyQt5.QtCore import (QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg, qInstallMessageHandler) +# Optional imports try: # pylint: disable=import-error from colorlog import ColoredFormatter except ImportError: ColoredFormatter = None +try: + # pylint: disable=import-error + import colorama +except ImportError: + colorama = None # The different loggers used. @@ -81,7 +87,8 @@ def init_log(args): else: console_fmt = simple_fmt console_fmt_colored = simple_fmt_colored - if (ColoredFormatter is not None and os.name == 'posix' and + stream = sys.stderr # Gets overwritten if we use colorama + if (ColoredFormatter is not None and (os.name == 'posix' or colorama) and sys.stderr.isatty() and args.color): console_formatter = ColoredFormatter( console_fmt_colored, datefmt, log_colors={ @@ -92,9 +99,13 @@ def init_log(args): 'CRITICAL': 'red', } ) + if colorama: + colorama.init() + stream = colorama.AnsiToWin32(sys.stderr) else: console_formatter = logging.Formatter(console_fmt, datefmt, '{') - console_handler = logging.StreamHandler() + + console_handler = logging.StreamHandler(stream) console_handler.addFilter(logfilter) console_handler.setLevel(level) console_handler.setFormatter(console_formatter) diff --git a/scripts/setupcommon.py b/scripts/setupcommon.py index bc42f71a5..205b2a2c7 100644 --- a/scripts/setupcommon.py +++ b/scripts/setupcommon.py @@ -77,6 +77,7 @@ setupdata = { 'author': qutebrowser.__author__, 'author_email': qutebrowser.__email__, 'license': qutebrowser.__license__, + 'extras_require': {'colorlog': ['colorlog', 'colorama']}, 'classifiers': [ 'Development Status :: 3 - Alpha', 'Environment :: X11 Applications :: Qt',