OLD | NEW |
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 sys |
9 import time | 10 import time |
10 | 11 |
11 | 12 |
12 class CustomFormatter(logging.Formatter): | 13 class CustomFormatter(logging.Formatter): |
13 """Custom log formatter.""" | 14 """Custom log formatter.""" |
14 | 15 |
15 #override | 16 #override |
16 def __init__(self, fmt='%(threadName)-4s %(message)s'): | 17 def __init__(self, fmt='%(threadName)-4s %(message)s'): |
17 # Can't use super() because in older Python versions logging.Formatter does | 18 # Can't use super() because in older Python versions logging.Formatter does |
18 # not inherit from object. | 19 # not inherit from object. |
(...skipping 21 matching lines...) Expand all Loading... |
40 | 41 |
41 def SetLogLevel(verbose_count): | 42 def SetLogLevel(verbose_count): |
42 """Sets log level as |verbose_count|.""" | 43 """Sets log level as |verbose_count|.""" |
43 log_level = logging.WARNING # Default. | 44 log_level = logging.WARNING # Default. |
44 if verbose_count == 1: | 45 if verbose_count == 1: |
45 log_level = logging.INFO | 46 log_level = logging.INFO |
46 elif verbose_count >= 2: | 47 elif verbose_count >= 2: |
47 log_level = logging.DEBUG | 48 log_level = logging.DEBUG |
48 logger = logging.getLogger() | 49 logger = logging.getLogger() |
49 logger.setLevel(log_level) | 50 logger.setLevel(log_level) |
50 custom_handler = logging.StreamHandler() | 51 custom_handler = logging.StreamHandler(sys.stdout) |
51 custom_handler.setFormatter(CustomFormatter()) | 52 custom_handler.setFormatter(CustomFormatter()) |
52 logging.getLogger().addHandler(custom_handler) | 53 logging.getLogger().addHandler(custom_handler) |
OLD | NEW |