Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements a CursorDebugWrapper to enable logging queries to console in debug mode #167

Merged
merged 1 commit into from
Nov 26, 2018

Conversation

RossRogers
Copy link
Contributor

@RossRogers RossRogers commented Nov 7, 2018

This is a port of django.db.backends.utils.CursorDebugWrapper. Implementing this only incurs a runtime cost when DEBUG=True for the project's settings.

With these edits you can then log to the console by putting this in your settings.py:

LOGGING = {
    'disable_existing_loggers': False,
    'version': 1,
    'handlers': {
        'console': {
            # logging handler that outputs log messages to terminal
            'class': 'logging.StreamHandler',
            'level': 'DEBUG', # message level to be written to console
        },
    },
    'loggers': {
        #'': {
        #    # this sets root level logger to log debug and higher level
        #    # logs to console. All other loggers inherit settings from
        #    # root level logger.
        #    'handlers': ['console'],
        #    'level': 'DEBUG',
        #    'propagate': False, # this tells logger to send logging message
        #                        # to its parent (will send if set to True)
        #},
        'django.db': {
            'level': 'DEBUG',
            'handlers': ['console'],
        },
        # 'django.db': {
        #     # django also has database level logging
        # },
    },
}

@dlo dlo self-requested a review November 7, 2018 23:39
@RossRogers RossRogers merged commit 1c385c7 into lionheart:django-2 Nov 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants