diff options
author | craigdh@chromium.org <craigdh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-09 18:00:32 +0000 |
---|---|---|
committer | craigdh@chromium.org <craigdh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-09 18:00:32 +0000 |
commit | 3c9ded90be62de83eac28c57c80b8afda3db2bb7 (patch) | |
tree | 44bd0d35d7b0aae69f124c29ad344c8bbf54d8a2 /build | |
parent | b2c7e152d138cbec55dda9f4b0b99d407ff62c59 (diff) | |
download | chromium_src-3c9ded90be62de83eac28c57c80b8afda3db2bb7.zip chromium_src-3c9ded90be62de83eac28c57c80b8afda3db2bb7.tar.gz chromium_src-3c9ded90be62de83eac28c57c80b8afda3db2bb7.tar.bz2 |
[android] Improve logging output.
BUG=160320
TEST=ran the tests
Review URL: https://codereview.chromium.org/13601030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193143 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build')
-rw-r--r-- | build/android/pylib/cmd_helper.py | 6 | ||||
-rw-r--r-- | build/android/pylib/utils/run_tests_helper.py | 26 |
2 files changed, 29 insertions, 3 deletions
diff --git a/build/android/pylib/cmd_helper.py b/build/android/pylib/cmd_helper.py index b6bbac7..6dcc911 100644 --- a/build/android/pylib/cmd_helper.py +++ b/build/android/pylib/cmd_helper.py @@ -10,6 +10,7 @@ import subprocess import constants + def RunCmd(args, cwd=None): """Opens a subprocess to execute a program and returns its return value. @@ -23,8 +24,7 @@ def RunCmd(args, cwd=None): Return code from the command execution. """ logging.info(str(args) + ' ' + (cwd or '')) - p = subprocess.Popen(args=args, cwd=cwd) - return p.wait() + return subprocess.call(args, cwd=cwd) def GetCmdOutput(args, cwd=None, shell=False): @@ -44,6 +44,7 @@ def GetCmdOutput(args, cwd=None, shell=False): (_, output) = GetCmdStatusAndOutput(args, cwd, shell) return output + def GetCmdStatusAndOutput(args, cwd=None, shell=False): """Executes a subprocess and returns its exit code and output. @@ -67,6 +68,7 @@ def GetCmdStatusAndOutput(args, cwd=None, shell=False): logging.info(stdout[:4096]) # Truncate output longer than 4k. return (exit_code, stdout) + class OutDirectory(object): _out_directory = os.path.join(constants.CHROME_DIR, 'out') @staticmethod diff --git a/build/android/pylib/utils/run_tests_helper.py b/build/android/pylib/utils/run_tests_helper.py index 15e5d53..b5730b6 100644 --- a/build/android/pylib/utils/run_tests_helper.py +++ b/build/android/pylib/utils/run_tests_helper.py @@ -6,6 +6,26 @@ import logging import os +import time + + +class CustomFormatter(logging.Formatter): + """Custom log formatter.""" + + #override + def __init__(self, fmt=''): + # Can't use super() because in older Python versions logging.Formatter does + # not inherit from object. + logging.Formatter.__init__(self, fmt=fmt) + self._creation_time = time.time() + + #override + def format(self, record): + # Can't use super() because in older Python versions logging.Formatter does + # not inherit from object. + msg = logging.Formatter.format(self, record) + timediff = str(int(time.time() - self._creation_time)) + return '%s %ss %s' % (record.levelname[0], timediff.rjust(4), msg) def GetExpectations(file_name): @@ -23,4 +43,8 @@ def SetLogLevel(verbose_count): log_level = logging.INFO elif verbose_count >= 2: log_level = logging.DEBUG - logging.getLogger().setLevel(log_level) + logger = logging.getLogger() + logger.setLevel(log_level) + custom_handler = logging.StreamHandler() + custom_handler.setFormatter(CustomFormatter()) + logging.getLogger().addHandler(custom_handler) |