OLD | NEW |
---|---|
(Empty) | |
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 | |
3 # found in the LICENSE file. | |
4 | |
5 import contextlib | |
6 import logging | |
7 | |
8 @contextlib.contextmanager | |
9 def SuppressLogging(level=logging.ERROR): | |
jbudorick
2015/01/26 16:07:32
My only comment on this is that handling levels as
| |
10 """Momentarilly suppress logging events from all loggers. | |
11 | |
12 TODO(jbudorick): This is not thread safe. Log events from other threads might | |
13 also inadvertently dissapear. | |
14 | |
15 Example: | |
16 | |
17 with logging_utils.SuppressLogging(): | |
18 # all but CRITICAL logging messages are suppressed | |
19 logging.info('just doing some thing') # not shown | |
20 logging.critical('something really bad happened') # still shown | |
21 | |
22 Args: | |
23 level: logging events with this or lower levels are suppressed. | |
24 """ | |
25 logging.disable(level) | |
26 yield | |
27 logging.disable(logging.NOTSET) | |
OLD | NEW |