Last active
June 14, 2019 18:15
-
-
Save iansan5653/28ce8ec2c50d507f0543b0b17cdc2637 to your computer and use it in GitHub Desktop.
Temporarily Disable Logging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import contextlib | |
import logging | |
@contextlib.contextmanager | |
def suppress_logs(logger: logging.Logger = logging.getLogger()): | |
"""Context manager to temporarily disable logs. | |
# Arguments | |
logger (logging.Logger): #logging.Logger object to disable. Defaults | |
to the root logger. | |
# Usage | |
```python | |
with suppress_logs(): | |
pass | |
``` | |
""" | |
logger.disabled = True | |
yield | |
logger.disabled = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment