avocado.core.output: Make OutputManager to handle pagination

One less than ideal aspect of our output module is that
plugins have to use a bunch of primitives of that module
out of necessity (such as get_paginator()).

Avocado needs a single entity that controls output for
the application. Let's start by covering the needs of
plugins, by introducing the list_mode argument to the
constructor of that class. When list_mode is set to
True, instead of the regular logging system we'll use
the output paginator class (that will use less if
available to display large amounts of output line with
pagination. Also, turn a useful method that was private
to public, ._log() -> .log().
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 12a1c8e4
......@@ -242,10 +242,27 @@ class OutputManager(object):
term_support.MOVE_BACK + THROBBER_STEPS[2],
term_support.MOVE_BACK + THROBBER_STEPS[3]]
def __init__(self, logger_name='avocado.app'):
self.console_log = logging.getLogger('avocado.app')
def __init__(self, console_logger='avocado.app', list_mode=False):
self.list_mode = list_mode
self.console_log = logging.getLogger(console_logger)
self.paginator = get_paginator()
self.throbber_pos = 0
def log(self, msg, level=logging.INFO, skip_newline=False):
"""
Write a message to the avocado.app logger or the paginator.
:param msg: Message to write
:type msg: string
"""
extra = {'skip_newline': skip_newline}
if self.list_mode:
if not skip_newline:
msg += '\n'
self.paginator.write(msg)
else:
self.console_log.log(level=level, msg=msg, extra=extra)
def throbber_progress(self, progress_from_test=False):
"""
Give an interactive indicator of the test progress
......@@ -267,16 +284,6 @@ class OutputManager(object):
else:
self.throbber_pos += 1
def _log(self, msg, level=logging.INFO, skip_newline=False):
"""
Write a message to the avocado.app logger.
:param msg: Message to write
:type msg: string
"""
extra = {'skip_newline': skip_newline}
self.console_log.log(level=level, msg=msg, extra=extra)
def start_file_logging(self, logfile, loglevel, unique_id):
"""
Start the main file logging.
......@@ -319,7 +326,7 @@ class OutputManager(object):
:param msg: Message to write.
"""
self._log(msg, level=logging.INFO, skip_newline=skip_newline)
self.log(msg, level=logging.INFO, skip_newline=skip_newline)
def error(self, msg):
"""
......@@ -327,7 +334,7 @@ class OutputManager(object):
:param msg: Message to write.
"""
self._log(msg, level=logging.ERROR)
self.log(msg, level=logging.ERROR)
def log_healthy(self, msg, skip_newline=False):
"""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册