Add a --force-color argument for logging
This commit is contained in:
parent
48d7185c94
commit
528e303d6e
@ -27,6 +27,8 @@ Added
|
|||||||
- New `:jump-mark` command to jump to a mark, bound to `'`
|
- New `:jump-mark` command to jump to a mark, bound to `'`
|
||||||
- New `:set-mark` command to set a mark, bound to ```(backtick)
|
- New `:set-mark` command to set a mark, bound to ```(backtick)
|
||||||
- The `'` mark gets set when moving away (hinting link with anchor, searching, etc.) so you can move back with `''`
|
- The `'` mark gets set when moving away (hinting link with anchor, searching, etc.) so you can move back with `''`
|
||||||
|
- New `--force-color` argument to force colored logging even if stdout is not a
|
||||||
|
terminal
|
||||||
|
|
||||||
Changed
|
Changed
|
||||||
~~~~~~~
|
~~~~~~~
|
||||||
|
@ -81,6 +81,9 @@ show it.
|
|||||||
*--nocolor*::
|
*--nocolor*::
|
||||||
Turn off colored logging.
|
Turn off colored logging.
|
||||||
|
|
||||||
|
*--force-color*::
|
||||||
|
Force colored logging
|
||||||
|
|
||||||
*--harfbuzz* '{old,new,system,auto}'::
|
*--harfbuzz* '{old,new,system,auto}'::
|
||||||
HarfBuzz engine version to use. Default: auto.
|
HarfBuzz engine version to use. Default: auto.
|
||||||
|
|
||||||
|
@ -88,6 +88,8 @@ def get_argparser():
|
|||||||
action='store_true')
|
action='store_true')
|
||||||
debug.add_argument('--nocolor', help="Turn off colored logging.",
|
debug.add_argument('--nocolor', help="Turn off colored logging.",
|
||||||
action='store_false', dest='color')
|
action='store_false', dest='color')
|
||||||
|
debug.add_argument('--force-color', help="Force colored logging",
|
||||||
|
action='store_true')
|
||||||
debug.add_argument('--harfbuzz', choices=['old', 'new', 'system', 'auto'],
|
debug.add_argument('--harfbuzz', choices=['old', 'new', 'system', 'auto'],
|
||||||
default='auto', help="HarfBuzz engine version to use. "
|
default='auto', help="HarfBuzz engine version to use. "
|
||||||
"Default: auto.")
|
"Default: auto.")
|
||||||
|
@ -150,7 +150,8 @@ def init_log(args):
|
|||||||
if numeric_level > logging.DEBUG and args.debug:
|
if numeric_level > logging.DEBUG and args.debug:
|
||||||
numeric_level = logging.DEBUG
|
numeric_level = logging.DEBUG
|
||||||
|
|
||||||
console, ram = _init_handlers(numeric_level, args.color, args.loglines)
|
console, ram = _init_handlers(numeric_level, args.color, args.force_color,
|
||||||
|
args.loglines)
|
||||||
root = logging.getLogger()
|
root = logging.getLogger()
|
||||||
if console is not None:
|
if console is not None:
|
||||||
if args.logfilter is not None:
|
if args.logfilter is not None:
|
||||||
@ -174,22 +175,24 @@ def disable_qt_msghandler():
|
|||||||
QtCore.qInstallMessageHandler(old_handler)
|
QtCore.qInstallMessageHandler(old_handler)
|
||||||
|
|
||||||
|
|
||||||
def _init_handlers(level, color, ram_capacity):
|
def _init_handlers(level, color, force_color, ram_capacity):
|
||||||
"""Init log handlers.
|
"""Init log handlers.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
level: The numeric logging level.
|
level: The numeric logging level.
|
||||||
color: Whether to use color if available.
|
color: Whether to use color if available.
|
||||||
|
force_color: Force colored output.
|
||||||
"""
|
"""
|
||||||
global ram_handler
|
global ram_handler
|
||||||
console_fmt, ram_fmt, html_fmt, use_colorama = _init_formatters(
|
console_fmt, ram_fmt, html_fmt, use_colorama = _init_formatters(
|
||||||
level, color)
|
level, color, force_color)
|
||||||
|
|
||||||
if sys.stderr is None:
|
if sys.stderr is None:
|
||||||
console_handler = None
|
console_handler = None
|
||||||
else:
|
else:
|
||||||
|
strip = False if force_color else None
|
||||||
if use_colorama:
|
if use_colorama:
|
||||||
stream = colorama.AnsiToWin32(sys.stderr)
|
stream = colorama.AnsiToWin32(sys.stderr, strip=strip)
|
||||||
else:
|
else:
|
||||||
stream = sys.stderr
|
stream = sys.stderr
|
||||||
console_handler = logging.StreamHandler(stream)
|
console_handler = logging.StreamHandler(stream)
|
||||||
@ -207,12 +210,13 @@ def _init_handlers(level, color, ram_capacity):
|
|||||||
return console_handler, ram_handler
|
return console_handler, ram_handler
|
||||||
|
|
||||||
|
|
||||||
def _init_formatters(level, color):
|
def _init_formatters(level, color, force_color):
|
||||||
"""Init log formatters.
|
"""Init log formatters.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
level: The numeric logging level.
|
level: The numeric logging level.
|
||||||
color: Whether to use color if available.
|
color: Whether to use color if available.
|
||||||
|
force_color: Force colored output.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
A (console_formatter, ram_formatter, use_colorama) tuple.
|
A (console_formatter, ram_formatter, use_colorama) tuple.
|
||||||
@ -232,7 +236,7 @@ def _init_formatters(level, color):
|
|||||||
return None, ram_formatter, html_formatter, False
|
return None, ram_formatter, html_formatter, False
|
||||||
use_colorama = False
|
use_colorama = False
|
||||||
if (colorlog is not None and (os.name == 'posix' or colorama) and
|
if (colorlog is not None and (os.name == 'posix' or colorama) and
|
||||||
sys.stderr.isatty() and color):
|
(sys.stderr.isatty() or force_color) and color):
|
||||||
console_formatter = colorlog.ColoredFormatter(
|
console_formatter = colorlog.ColoredFormatter(
|
||||||
console_fmt_colored, DATEFMT, log_colors=LOG_COLORS)
|
console_fmt_colored, DATEFMT, log_colors=LOG_COLORS)
|
||||||
if colorama and os.name != 'posix':
|
if colorama and os.name != 'posix':
|
||||||
|
Loading…
Reference in New Issue
Block a user