How to stop sql logging in debug mode?

后端 未结 1 1464
醉话见心
醉话见心 2021-01-13 20:03

How do I run django in debug=True without being bombarded by the sql logging?

Being forced to squint through all this noise is making it rather hard to see my debu

相关标签:
1条回答
  • 2021-01-13 20:44

    In Django 1.3 this can be done rather simply with the inclusion of logging. In summary the way I do it is very similar to the docs and keep the focus of logging on my application. My settings.py file currently looks like this.

    # See http://docs.djangoproject.com/en/dev/topics/logging for
    # more details on how to customize your logging configuration.
    LOGGING = {
        'version': 1,
        'disable_existing_loggers': True,
        'formatters': {
            'standard': {
                'format': "[%(asctime)s] %(levelname)s [%(name)s] %(message)s",
                'datefmt': "%d/%b/%Y %H:%M:%S"
            },
        },
        'handlers': {
            'null': {
                'level': 'DEBUG',
                'class': 'django.utils.log.NullHandler',
            },
            'console': {
                'level': 'DEBUG',
                'class': 'logging.StreamHandler',
                'formatter': 'standard'
            },
        },
        'loggers': {
            'django': {
                'handlers': ['console'],
                'propagate': True,
                'level': 'INFO',
            },
            'django.db.backends': {
                'handlers': ['console'],
                'level': 'ERROR',
                'propagate': False,
            },
            'apps': {
                'handlers': ['console'],
                'level': 'DEBUG',
            },
        }
    }
    

    If you are using an older version of Django you can setup logging by using filters (Yes you can do this in 1.3 too.) This SO post should provide you with what you need to get going.

    Edit Update

    Again following the documentation which gives an example combined with this post should get you where you need to go.

    1. Add in a django handler and propagate it down the chain..
    2. Add in a django.db.backends which doesn't propagate but raise the noise floor to ERROR

    I don't think there is anything else?

    HTH

    0 讨论(0)
提交回复
热议问题