Support colorama to get colored logs on windows

This commit is contained in:
Florian Bruhin 2014-06-06 12:13:32 +02:00
parent fd220b1b36
commit e6893af3d4
2 changed files with 14 additions and 2 deletions

View File

@ -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)

View File

@ -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',