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

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

Issue 13601030: [android] Improve logging output. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: old Python compatability Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « build/android/pylib/cmd_helper.py ('k') | 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 python test runners.""" 5 """Helper functions common to native, java and python test runners."""
6 6
7 import logging 7 import logging
8 import os 8 import os
9 import time
10
11
12 class CustomFormatter(logging.Formatter):
13 """Custom log formatter."""
14
15 #override
16 def __init__(self, fmt=''):
17 # Can't use super() because in older Python versions logging.Formatter does
18 # not inherit from object.
19 logging.Formatter.__init__(self, fmt=fmt)
20 self._creation_time = time.time()
21
22 #override
23 def format(self, record):
24 # Can't use super() because in older Python versions logging.Formatter does
25 # not inherit from object.
26 msg = logging.Formatter.format(self, record)
27 timediff = str(int(time.time() - self._creation_time))
28 return '%s %ss %s' % (record.levelname[0], timediff.rjust(4), msg)
9 29
10 30
11 def GetExpectations(file_name): 31 def GetExpectations(file_name):
12 """Returns a list of test names in the |file_name| test expectations file.""" 32 """Returns a list of test names in the |file_name| test expectations file."""
13 if not file_name or not os.path.exists(file_name): 33 if not file_name or not os.path.exists(file_name):
14 return [] 34 return []
15 return [x for x in [x.strip() for x in file(file_name).readlines()] 35 return [x for x in [x.strip() for x in file(file_name).readlines()]
16 if x and x[0] != '#'] 36 if x and x[0] != '#']
17 37
18 38
19 def SetLogLevel(verbose_count): 39 def SetLogLevel(verbose_count):
20 """Sets log level as |verbose_count|.""" 40 """Sets log level as |verbose_count|."""
21 log_level = logging.WARNING # Default. 41 log_level = logging.WARNING # Default.
22 if verbose_count == 1: 42 if verbose_count == 1:
23 log_level = logging.INFO 43 log_level = logging.INFO
24 elif verbose_count >= 2: 44 elif verbose_count >= 2:
25 log_level = logging.DEBUG 45 log_level = logging.DEBUG
26 logging.getLogger().setLevel(log_level) 46 logger = logging.getLogger()
47 logger.setLevel(log_level)
48 custom_handler = logging.StreamHandler()
49 custom_handler.setFormatter(CustomFormatter())
50 logging.getLogger().addHandler(custom_handler)
OLDNEW
« no previous file with comments | « build/android/pylib/cmd_helper.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698