提交 682b1d78 编写于 作者: L Lukáš Doktor 提交者: Cleber Rosa

avocado.core.output: Add support to specify level in --show

The logging stream can be optionally followed by ":$LOG_LEVEL" either
using number, or the symbolic python logging level (INFO).
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 dcb23157
......@@ -18,8 +18,10 @@ Manages output and logging in avocado applications.
from StringIO import StringIO
import logging
import os
import re
import sys
from . import exit_codes
from ..utils import path as utils_path
from .settings import settings
......@@ -34,6 +36,15 @@ else:
STDOUT = sys.stdout
STDERR = sys.stderr
BUILTIN_STREAMS = {'app': 'application output',
'test': 'test output',
'debug': 'tracebacks and other debugging info',
'remote': 'fabric/paramiko debug',
'early': 'early logging of other streams (very verbose)'}
BUILTIN_STREAM_SETS = {'all': 'all builtin streams',
'none': 'disable console logging completely'}
def early_start():
"""
......@@ -126,6 +137,21 @@ def reconfigure(args):
disable_log_handler("avocado.app.debug")
enable_stderr()
# Add custom loggers
for name in [_ for _ in enabled if _ not in BUILTIN_STREAMS.iterkeys()]:
stream_level = re.split(r'(?<!\\):', name, maxsplit=1)
name = stream_level[0]
if len(stream_level) == 1:
level = logging.DEBUG
else:
level = (int(name[1]) if name[1].isdigit()
else logging.getLevelName(name[1].upper()))
try:
add_log_handler(name, logging.StreamHandler, STDERR, level)
except ValueError, details:
app_logger.error("Failed to set logger for --show %s:%s: %s.",
name, level, details)
sys.exit(exit_codes.AVOCADO_FAIL)
# Remove the in-memory handlers
for handler in logging.root.handlers:
if isinstance(handler, MemStreamHandler):
......
......@@ -23,37 +23,13 @@ import sys
from . import exit_codes
from . import tree
from . import settings
from .output import BUILTIN_STREAMS, BUILTIN_STREAM_SETS
from .version import VERSION
PROG = 'avocado'
DESCRIPTION = 'Avocado Test Runner'
def log_type(value):
valid_streams = ["app", "test", "debug", "remote", "early", "all", "none"]
value = value.split(',')
if any(_ not in valid_streams for _ in value):
missing = [_ for _ in value if _ not in valid_streams]
msg = ("Invalid logging stream(s): %s\n"
"Supported logging streams are:\n"
" app - application output\n"
" test - test output\n"
" debug - tracebacks and other debugging info\n"
" remote - fabric/paramiko debug\n"
" early - early logging of other streams (very verbose)\n"
" all - everything\n"
" none - disable everything\n" % ", ".join(missing))
sys.stderr.write(msg)
sys.exit(-1)
if 'all' in value:
return ["app", "test", "debug", "remote", "early"]
elif 'none' in value:
return []
else:
return value
class ArgumentParser(argparse.ArgumentParser):
"""
......@@ -82,12 +58,18 @@ class Parser(object):
version='Avocado %s' % VERSION)
self.application.add_argument('--config', metavar='CONFIG_FILE',
help='Use custom configuration from a file')
streams = (['"%s": %s' % _ for _ in BUILTIN_STREAMS.iteritems()] +
['"%s": %s' % _ for _ in BUILTIN_STREAM_SETS.iteritems()])
streams = "; ".join(streams)
self.application.add_argument('--show', action="store",
type=log_type,
metavar='STREAMS', default=['app'],
help="Comma separated list of logging "
"streams to be enabled (app,test,debug,"
"remote,early); By default 'app'")
type=lambda value: value.split(","),
metavar="STREAM[:LVL]",
default=['app'], help="List of comma "
"separated builtin logs, or logging "
"streams optionally followed by LEVEL "
"(DEBUG,INFO,...). Builtin streams "
"are: %s. By default: 'app'"
% streams)
def start(self):
"""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册