Skip to content

Instantly share code, notes, and snippets.

@iansan5653
Last active June 14, 2019 18:15
Show Gist options
  • Save iansan5653/28ce8ec2c50d507f0543b0b17cdc2637 to your computer and use it in GitHub Desktop.
Save iansan5653/28ce8ec2c50d507f0543b0b17cdc2637 to your computer and use it in GitHub Desktop.
Temporarily Disable Logging
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