Created
May 20, 2016 10:21
-
-
Save TigerND/5623fc2312bd0a2626f7f82d0ba79bec to your computer and use it in GitHub Desktop.
This file contains 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
from contextlib import contextmanager | |
from django.conf import settings | |
import logging | |
logger = logging.getLogger(__name__) | |
django_db_backends_logger = logging.getLogger('django.db.backends') | |
@contextmanager | |
def debug_db_backends(enabled=settings.DEBUG, level=logging.DEBUG): | |
old_level = django_db_backends_logger.level | |
if (enabled): | |
django_db_backends_logger.setLevel(level) | |
yield | |
if (enabled): | |
django_db_backends_logger.setLevel(old_level) | |
# Example usage: | |
with debug_db_backends(settings.DEBUG): | |
from .operation import Operation | |
return Operation.objects.filter( | |
transaction__block__blockchain__id=42 | |
).count() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment