turn off SQL logging while keeping settings.DEBUG?

前端 未结 4 713
生来不讨喜
生来不讨喜 2020-12-14 01:31

Django logs SQL operations to an internal buffer (whether logging to file or not) when settings.DEBUG=True. Because I have long-running process that does a lot of DB operat

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 02:06

    Yes, you can quiet the sql logging down by assigning a 'null handler' to the logger named 'django.db.backends'. I assume you use django's new dict-based logging setup? If so, this snippet ought to make it easy:

        ...
        'handlers': {
            'null': {
                'level': 'DEBUG',
                'class':'logging.NullHandler',
                },
        ...
        'loggers': {
            ... your regular logger 'root' or '' ....
            'django.db.backends': {
                'handlers': ['null'],  # Quiet by default!
                'propagate': False,
                'level':'DEBUG',
                },
        ...
    

    Update: look at Brian's answer, too. I understood "logging" to mean the irritating logging of every sql statement. Brian talks about the internal memory logging of every query (and I guess he's right :-)

提交回复
热议问题