Search code examples
pythondjangohttpresponse

Django: Shut off console output of http response messages


So we made an app with django and it prints all these http response messages on the console everytime it gets a request.

[Date String] 'GET /urlpath/..blah blah ' 200 216
[Date String] 'DELETE /anotherurl/..blah blah ' 200 205 
...
..

We have disabled all logger outputs. Set Debug=False. Tried 'python manage.py runserver --verbosity 0'. Even tried changing sys.stdout to a NullDevice() class. Yet, we can't seem to turn off these response messages which are slowing the server to a crawl. All other messages get turned off, except these. Any suggestions?

I realize that the django internal webserver is meant only for development and not for production, but we would like to get a fair amount of speed just with the developmental version itself (without having to go into the intricacies of deploying django behind Apache/lighttpd).


Solution

  • All you need just to Add in Django logging settings:

        'loggers': {
            # django's default logger
            'django.server': {
                'handlers': ['django.server'],
                'level': 'INFO',
                'propagate': False,
            },
        }
    

    you can override Django's default loggers: https://github.com/django/django/blob/32265361279b3316f5bce8efa71f2049409461e3/django/utils/log.py#L18

    How Django's default built-in loggers works: https://docs.djangoproject.com/en/1.10/topics/logging/#id3

    using custom CallbackFilter filter: https://docs.djangoproject.com/en/1.10/topics/logging/#django.utils.log.CallbackFilter