Merge branch 'format-debug-log-level' of https://github.com/ryanjmortenson/qutebrowser into ryanjmortenson-format-debug-log-level
This commit is contained in:
commit
29778bb799
@ -259,6 +259,7 @@ def debug_log_level(level: str):
|
|||||||
Args:
|
Args:
|
||||||
level: The log level to set.
|
level: The log level to set.
|
||||||
"""
|
"""
|
||||||
|
log.change_console_formatter(log.LOG_LEVELS[level.upper()])
|
||||||
log.console_handler.setLevel(log.LOG_LEVELS[level.upper()])
|
log.console_handler.setLevel(log.LOG_LEVELS[level.upper()])
|
||||||
|
|
||||||
|
|
||||||
|
@ -250,6 +250,18 @@ def _init_handlers(level, color, force_color, json_logging, ram_capacity):
|
|||||||
return console_handler, ram_handler
|
return console_handler, ram_handler
|
||||||
|
|
||||||
|
|
||||||
|
def get_console_format(level):
|
||||||
|
"""Get format.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
level: The numeric logging level.
|
||||||
|
|
||||||
|
Return:
|
||||||
|
Format of the requested level.
|
||||||
|
"""
|
||||||
|
return EXTENDED_FMT if level <= logging.DEBUG else SIMPLE_FMT
|
||||||
|
|
||||||
|
|
||||||
def _init_formatters(level, color, force_color, json_logging):
|
def _init_formatters(level, color, force_color, json_logging):
|
||||||
"""Init log formatters.
|
"""Init log formatters.
|
||||||
|
|
||||||
@ -264,7 +276,7 @@ def _init_formatters(level, color, force_color, json_logging):
|
|||||||
console_formatter/ram_formatter: logging.Formatter instances.
|
console_formatter/ram_formatter: logging.Formatter instances.
|
||||||
use_colorama: Whether to use colorama.
|
use_colorama: Whether to use colorama.
|
||||||
"""
|
"""
|
||||||
console_fmt = EXTENDED_FMT if level <= logging.DEBUG else SIMPLE_FMT
|
console_fmt = get_console_format(level)
|
||||||
ram_formatter = ColoredFormatter(EXTENDED_FMT, DATEFMT, '{',
|
ram_formatter = ColoredFormatter(EXTENDED_FMT, DATEFMT, '{',
|
||||||
use_colors=False)
|
use_colors=False)
|
||||||
html_formatter = HTMLFormatter(EXTENDED_FMT_HTML, DATEFMT,
|
html_formatter = HTMLFormatter(EXTENDED_FMT_HTML, DATEFMT,
|
||||||
@ -291,6 +303,23 @@ def _init_formatters(level, color, force_color, json_logging):
|
|||||||
return console_formatter, ram_formatter, html_formatter, use_colorama
|
return console_formatter, ram_formatter, html_formatter, use_colorama
|
||||||
|
|
||||||
|
|
||||||
|
def change_console_formatter(level):
|
||||||
|
"""Change console formatter based on level.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
level: The numeric logging level
|
||||||
|
"""
|
||||||
|
if not isinstance(console_handler.formatter, ColoredFormatter):
|
||||||
|
# JSON Formatter being used for end2end tests
|
||||||
|
pass
|
||||||
|
|
||||||
|
use_colors = console_handler.formatter.use_colors
|
||||||
|
console_fmt = get_console_format(level)
|
||||||
|
console_formatter = ColoredFormatter(console_fmt, DATEFMT, '{',
|
||||||
|
use_colors=use_colors)
|
||||||
|
console_handler.setFormatter(console_formatter)
|
||||||
|
|
||||||
|
|
||||||
def qt_message_handler(msg_type, context, msg):
|
def qt_message_handler(msg_type, context, msg):
|
||||||
"""Qt message handler to redirect qWarning etc. to the logging system.
|
"""Qt message handler to redirect qWarning etc. to the logging system.
|
||||||
|
|
||||||
@ -539,10 +568,10 @@ class ColoredFormatter(logging.Formatter):
|
|||||||
|
|
||||||
def __init__(self, fmt, datefmt, style, *, use_colors):
|
def __init__(self, fmt, datefmt, style, *, use_colors):
|
||||||
super().__init__(fmt, datefmt, style)
|
super().__init__(fmt, datefmt, style)
|
||||||
self._use_colors = use_colors
|
self.use_colors = use_colors
|
||||||
|
|
||||||
def format(self, record):
|
def format(self, record):
|
||||||
if self._use_colors:
|
if self.use_colors:
|
||||||
color_dict = dict(COLOR_ESCAPES)
|
color_dict = dict(COLOR_ESCAPES)
|
||||||
color_dict['reset'] = RESET_ESCAPE
|
color_dict['reset'] = RESET_ESCAPE
|
||||||
log_color = LOG_COLORS[record.levelname]
|
log_color = LOG_COLORS[record.levelname]
|
||||||
|
Loading…
Reference in New Issue
Block a user