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.
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.
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
23 level: logging events with this or lower levels are suppressed.
25 logging
.disable(level
)
27 logging
.disable(logging
.NOTSET
)