Disable coloring when requested/on Windows/no tty

This commit is contained in:
Florian Bruhin 2014-05-25 20:08:07 +02:00
parent e89fc3d940
commit b37ca744b2
2 changed files with 14 additions and 9 deletions

View File

@ -171,6 +171,8 @@ class QuteBrowser(QApplication):
"(empty for no config storage)")
parser.add_argument('-d', '--debug', help="Turn on debugging options.",
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 "
"on startup.", metavar=':command')
# URLs will actually be in command

View File

@ -17,6 +17,8 @@
"""Loggers and utilities related to logging."""
import os
import sys
import logging
from logging import getLogger
from collections import deque
@ -70,16 +72,15 @@ def init_log(args):
datefmt = '%H:%M:%S'
if numeric_level <= logging.DEBUG:
console_fmt = (extended_fmt if ColoredFormatter is None
else extended_fmt_colored)
console_fmt = extended_fmt
console_fmt_colored = extended_fmt_colored
else:
console_fmt = (simple_fmt if ColoredFormatter is None
else simple_fmt_colored)
if ColoredFormatter is None:
console_formatter = logging.Formatter(console_fmt, datefmt, '{')
else:
console_formatter = ColoredFormatter(console_fmt, datefmt,
log_colors={
console_fmt = simple_fmt
console_fmt_colored = simple_fmt_colored
if (ColoredFormatter is not None and os.name == 'posix' and
sys.stderr.isatty() and args.color):
console_formatter = ColoredFormatter(
console_fmt_colored, datefmt, log_colors={
'DEBUG': 'cyan',
'INFO': 'green',
'WARNING': 'yellow',
@ -87,6 +88,8 @@ def init_log(args):
'CRITICAL': 'red',
}
)
else:
console_formatter = logging.Formatter(console_fmt, datefmt, '{')
console_handler = logging.StreamHandler()
console_handler.addFilter(logfilter)
console_handler.setLevel(level)