Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: build/android/pylib/utils/run_tests_helper.py

Issue 327823004: Adding milliseconds to test timestamps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed format to 8.3f to better match original. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Helper functions common to native, java and host-driven test runners.""" 5 """Helper functions common to native, java and host-driven test runners."""
6 6
7 import logging 7 import logging
8 import sys 8 import sys
9 import time 9 import time
10 10
11 11
12 class CustomFormatter(logging.Formatter): 12 class CustomFormatter(logging.Formatter):
13 """Custom log formatter.""" 13 """Custom log formatter."""
14 14
15 #override 15 #override
16 def __init__(self, fmt='%(threadName)-4s %(message)s'): 16 def __init__(self, fmt='%(threadName)-4s %(message)s'):
17 # Can't use super() because in older Python versions logging.Formatter does 17 # Can't use super() because in older Python versions logging.Formatter does
18 # not inherit from object. 18 # not inherit from object.
19 logging.Formatter.__init__(self, fmt=fmt) 19 logging.Formatter.__init__(self, fmt=fmt)
20 self._creation_time = time.time() 20 self._creation_time = time.time()
21 21
22 #override 22 #override
23 def format(self, record): 23 def format(self, record):
24 # Can't use super() because in older Python versions logging.Formatter does 24 # Can't use super() because in older Python versions logging.Formatter does
25 # not inherit from object. 25 # not inherit from object.
26 msg = logging.Formatter.format(self, record) 26 msg = logging.Formatter.format(self, record)
27 if 'MainThread' in msg[:19]: 27 if 'MainThread' in msg[:19]:
28 msg = msg.replace('MainThread', 'Main', 1) 28 msg = msg.replace('MainThread', 'Main', 1)
29 timediff = str(int(time.time() - self._creation_time)) 29 timediff = time.time() - self._creation_time
30 return '%s %ss %s' % (record.levelname[0], timediff.rjust(4), msg) 30 return '%s %8.3fs %s' % (record.levelname[0], timediff, msg)
31 31
32 32
33 def SetLogLevel(verbose_count): 33 def SetLogLevel(verbose_count):
34 """Sets log level as |verbose_count|.""" 34 """Sets log level as |verbose_count|."""
35 log_level = logging.WARNING # Default. 35 log_level = logging.WARNING # Default.
36 if verbose_count == 1: 36 if verbose_count == 1:
37 log_level = logging.INFO 37 log_level = logging.INFO
38 elif verbose_count >= 2: 38 elif verbose_count >= 2:
39 log_level = logging.DEBUG 39 log_level = logging.DEBUG
40 logger = logging.getLogger() 40 logger = logging.getLogger()
41 logger.setLevel(log_level) 41 logger.setLevel(log_level)
42 custom_handler = logging.StreamHandler(sys.stdout) 42 custom_handler = logging.StreamHandler(sys.stdout)
43 custom_handler.setFormatter(CustomFormatter()) 43 custom_handler.setFormatter(CustomFormatter())
44 logging.getLogger().addHandler(custom_handler) 44 logging.getLogger().addHandler(custom_handler)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698