Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / build / android / pylib / utils / logging_utils.py
blob1e46fa82080629d5b9acc5e97601835d1dd476fd
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.
5 import contextlib
6 import logging
8 @contextlib.contextmanager
9 def SuppressLogging(level=logging.ERROR):
10 """Momentarilly suppress logging events from all loggers.
12 TODO(jbudorick): This is not thread safe. Log events from other threads might
13 also inadvertently dissapear.
15 Example:
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
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)