Index: build/android/pylib/utils/run_tests_helper.py |
diff --git a/build/android/pylib/utils/run_tests_helper.py b/build/android/pylib/utils/run_tests_helper.py |
index 15e5d5381bcc9b6d9a3e97dcbed40191556a9904..b5730b6893aa544b2096772fc95180fd992b3d7a 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) |