| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import contextlib | 5 import contextlib |
| 6 import logging | 6 import logging |
| 7 import os | 7 import os |
| 8 import sys | |
| 9 | 8 |
| 10 from pylib import constants | 9 from pylib.constants import host_paths |
| 11 sys.path.insert(0, os.path.join(constants.DIR_SOURCE_ROOT, | 10 |
| 12 'third_party', 'colorama', 'src')) | 11 _COLORAMA_PATH = os.path.join( |
| 13 import colorama | 12 host_paths.DIR_SOURCE_ROOT, 'third_party', 'colorama', 'src') |
| 13 |
| 14 with host_paths.SysPath(_COLORAMA_PATH): |
| 15 import colorama |
| 14 | 16 |
| 15 class ColorStreamHandler(logging.StreamHandler): | 17 class ColorStreamHandler(logging.StreamHandler): |
| 16 """Handler that can be used to colorize logging output. | 18 """Handler that can be used to colorize logging output. |
| 17 | 19 |
| 18 Example using a specific logger: | 20 Example using a specific logger: |
| 19 | 21 |
| 20 logger = logging.getLogger('my_logger') | 22 logger = logging.getLogger('my_logger') |
| 21 logger.addHandler(ColorStreamHandler()) | 23 logger.addHandler(ColorStreamHandler()) |
| 22 logger.info('message') | 24 logger.info('message') |
| 23 | 25 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 # all but CRITICAL logging messages are suppressed | 89 # all but CRITICAL logging messages are suppressed |
| 88 logging.info('just doing some thing') # not shown | 90 logging.info('just doing some thing') # not shown |
| 89 logging.critical('something really bad happened') # still shown | 91 logging.critical('something really bad happened') # still shown |
| 90 | 92 |
| 91 Args: | 93 Args: |
| 92 level: logging events with this or lower levels are suppressed. | 94 level: logging events with this or lower levels are suppressed. |
| 93 """ | 95 """ |
| 94 logging.disable(level) | 96 logging.disable(level) |
| 95 yield | 97 yield |
| 96 logging.disable(logging.NOTSET) | 98 logging.disable(logging.NOTSET) |
| OLD | NEW |