Disable coloring when requested/on Windows/no tty
This commit is contained in:
parent
e89fc3d940
commit
b37ca744b2
@ -171,6 +171,8 @@ class QuteBrowser(QApplication):
|
|||||||
"(empty for no config storage)")
|
"(empty for no config storage)")
|
||||||
parser.add_argument('-d', '--debug', help="Turn on debugging options.",
|
parser.add_argument('-d', '--debug', help="Turn on debugging options.",
|
||||||
action='store_true')
|
action='store_true')
|
||||||
|
parser.add_argument('--nocolor', help="Turn off colored logging.",
|
||||||
|
action='store_false', dest='color')
|
||||||
parser.add_argument('command', nargs='*', help="Commands to execute "
|
parser.add_argument('command', nargs='*', help="Commands to execute "
|
||||||
"on startup.", metavar=':command')
|
"on startup.", metavar=':command')
|
||||||
# URLs will actually be in command
|
# URLs will actually be in command
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
"""Loggers and utilities related to logging."""
|
"""Loggers and utilities related to logging."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
import logging
|
import logging
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from collections import deque
|
from collections import deque
|
||||||
@ -70,16 +72,15 @@ def init_log(args):
|
|||||||
datefmt = '%H:%M:%S'
|
datefmt = '%H:%M:%S'
|
||||||
|
|
||||||
if numeric_level <= logging.DEBUG:
|
if numeric_level <= logging.DEBUG:
|
||||||
console_fmt = (extended_fmt if ColoredFormatter is None
|
console_fmt = extended_fmt
|
||||||
else extended_fmt_colored)
|
console_fmt_colored = extended_fmt_colored
|
||||||
else:
|
else:
|
||||||
console_fmt = (simple_fmt if ColoredFormatter is None
|
console_fmt = simple_fmt
|
||||||
else simple_fmt_colored)
|
console_fmt_colored = simple_fmt_colored
|
||||||
if ColoredFormatter is None:
|
if (ColoredFormatter is not None and os.name == 'posix' and
|
||||||
console_formatter = logging.Formatter(console_fmt, datefmt, '{')
|
sys.stderr.isatty() and args.color):
|
||||||
else:
|
console_formatter = ColoredFormatter(
|
||||||
console_formatter = ColoredFormatter(console_fmt, datefmt,
|
console_fmt_colored, datefmt, log_colors={
|
||||||
log_colors={
|
|
||||||
'DEBUG': 'cyan',
|
'DEBUG': 'cyan',
|
||||||
'INFO': 'green',
|
'INFO': 'green',
|
||||||
'WARNING': 'yellow',
|
'WARNING': 'yellow',
|
||||||
@ -87,6 +88,8 @@ def init_log(args):
|
|||||||
'CRITICAL': 'red',
|
'CRITICAL': 'red',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
console_formatter = logging.Formatter(console_fmt, datefmt, '{')
|
||||||
console_handler = logging.StreamHandler()
|
console_handler = logging.StreamHandler()
|
||||||
console_handler.addFilter(logfilter)
|
console_handler.addFilter(logfilter)
|
||||||
console_handler.setLevel(level)
|
console_handler.setLevel(level)
|
||||||
|
Loading…
Reference in New Issue
Block a user