Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

logging request urls in django

From advanced logging, I am able to get debug level logs for database calls, but cannot figure out how to get request URLs logged.

    # Log Django URL requests
    'django.request': {
        'handlers': ['console'],
        'propagate': False,
        'level': 'DEBUG',
    },
    'django': {
        'handlers': ['console'],
        'propagate': False,
        'level': 'WARNING',
    },

https://docs.djangoproject.com/en/1.9/topics/logging/ was not too helpful here. Is logging URL requests for debugging even supported?

like image 479
Speedy99 Avatar asked Mar 29 '16 21:03

Speedy99


2 Answers

While the current accepted answer is correct about django.request, there have been some updates:

https://docs.djangoproject.com/en/1.11/topics/logging/#django-server

django.server (added in Django 1.10) logger logs all requests when log level is INFO.

(note: only works with manage.py runserver - but you shouldn't be using Django log requests in production anyway; there's nginx or similar for that.)

like image 188
elnygren Avatar answered Nov 05 '22 21:11

elnygren


Quick search for logging in Django source suggests there is no logging of URL hits.

The django.request logger seems to be used only when there are errors (500) or warnings (404, etc).

You can use a custom middleware that logs all request URLs.

like image 43
Kedar Avatar answered Nov 05 '22 19:11

Kedar