Support colorama to get colored logs on windows
This commit is contained in:
parent
fd220b1b36
commit
e6893af3d4
@ -26,11 +26,17 @@ from collections import deque
|
|||||||
|
|
||||||
from PyQt5.QtCore import (QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg,
|
from PyQt5.QtCore import (QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg,
|
||||||
qInstallMessageHandler)
|
qInstallMessageHandler)
|
||||||
|
# Optional imports
|
||||||
try:
|
try:
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from colorlog import ColoredFormatter
|
from colorlog import ColoredFormatter
|
||||||
except ImportError:
|
except ImportError:
|
||||||
ColoredFormatter = None
|
ColoredFormatter = None
|
||||||
|
try:
|
||||||
|
# pylint: disable=import-error
|
||||||
|
import colorama
|
||||||
|
except ImportError:
|
||||||
|
colorama = None
|
||||||
|
|
||||||
# The different loggers used.
|
# The different loggers used.
|
||||||
|
|
||||||
@ -81,7 +87,8 @@ def init_log(args):
|
|||||||
else:
|
else:
|
||||||
console_fmt = simple_fmt
|
console_fmt = simple_fmt
|
||||||
console_fmt_colored = simple_fmt_colored
|
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):
|
sys.stderr.isatty() and args.color):
|
||||||
console_formatter = ColoredFormatter(
|
console_formatter = ColoredFormatter(
|
||||||
console_fmt_colored, datefmt, log_colors={
|
console_fmt_colored, datefmt, log_colors={
|
||||||
@ -92,9 +99,13 @@ def init_log(args):
|
|||||||
'CRITICAL': 'red',
|
'CRITICAL': 'red',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
if colorama:
|
||||||
|
colorama.init()
|
||||||
|
stream = colorama.AnsiToWin32(sys.stderr)
|
||||||
else:
|
else:
|
||||||
console_formatter = logging.Formatter(console_fmt, datefmt, '{')
|
console_formatter = logging.Formatter(console_fmt, datefmt, '{')
|
||||||
console_handler = logging.StreamHandler()
|
|
||||||
|
console_handler = logging.StreamHandler(stream)
|
||||||
console_handler.addFilter(logfilter)
|
console_handler.addFilter(logfilter)
|
||||||
console_handler.setLevel(level)
|
console_handler.setLevel(level)
|
||||||
console_handler.setFormatter(console_formatter)
|
console_handler.setFormatter(console_formatter)
|
||||||
|
@ -77,6 +77,7 @@ setupdata = {
|
|||||||
'author': qutebrowser.__author__,
|
'author': qutebrowser.__author__,
|
||||||
'author_email': qutebrowser.__email__,
|
'author_email': qutebrowser.__email__,
|
||||||
'license': qutebrowser.__license__,
|
'license': qutebrowser.__license__,
|
||||||
|
'extras_require': {'colorlog': ['colorlog', 'colorama']},
|
||||||
'classifiers': [
|
'classifiers': [
|
||||||
'Development Status :: 3 - Alpha',
|
'Development Status :: 3 - Alpha',
|
||||||
'Environment :: X11 Applications :: Qt',
|
'Environment :: X11 Applications :: Qt',
|
||||||
|
Loading…
Reference in New Issue
Block a user