Bug 1026181 - Make mach terminal formatter work outside mach context, r=wlach

--HG--
extra : rebase_source : ac66edb9f80fc5fbebebb953ca15861a91095d4b
This commit is contained in:
James Graham 2014-06-20 19:41:04 +01:00
parent edd72c0670
commit ae9da8bce3
3 changed files with 17 additions and 2 deletions

View File

@ -62,7 +62,7 @@ def add_logging_group(parser):
help=help_str)
def setup_logging(suite, args, defaults):
def setup_logging(suite, args, defaults=None):
"""
Configure a structuredlogger based on command line arguments.
@ -73,7 +73,10 @@ def setup_logging(suite, args, defaults):
:param args: A dictionary of {argument_name:value} produced from
parsing the command line arguments for the application
:param defaults: A dictionary of {formatter name: output stream} to apply
when there is no logging supplied on the command line.
when there is no logging supplied on the command line. If
this isn't supplied, reasonable defaults are chosen
(coloured mach formatting if stdout is a terminal, or raw
logs otherwise).
:rtype: StructuredLogger
"""
@ -83,6 +86,13 @@ def setup_logging(suite, args, defaults):
found_stdout_logger = False
if not hasattr(args, 'iteritems'):
args = vars(args)
if defaults is None:
if sys.__stdout__.isatty():
defaults = {"mach_terminal": sys.stdout}
else:
defaults = {"raw": sys.stdout}
for name, values in args.iteritems():
if name.startswith(prefix) and values is not None:
for value in values:

View File

@ -4,6 +4,8 @@
import time
import blessings
import base
@ -134,6 +136,8 @@ class MachTerminalFormatter(BaseMachFormatter):
"""
def __init__(self, start_time=None, write_interval=False, write_times=True,
terminal=None):
if terminal is None:
terminal = blessings.Terminal()
self.terminal = terminal
BaseMachFormatter.__init__(self,
start_time=start_time,

View File

@ -17,6 +17,7 @@ setup(name=PACKAGE_NAME,
license='MPL 1.1/GPL 2.0/LGPL 2.1',
packages=find_packages(),
zip_safe=False,
install_requires=["blessings>=1.3"],
tests_require=['mozfile'],
platforms =['Any'],
classifiers=['Development Status :: 4 - Beta',