6

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?

Speedy99
  • 1,691
  • 15
  • 15

3 Answers3

4

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.)

elnygren
  • 5,000
  • 4
  • 20
  • 31
1

I'm guessing you have defined console in handlers. If so, do check that you have set the appropriate level of DEBUG there. By default, it is set to INFO.

Roshan
  • 1,937
  • 1
  • 13
  • 25
  • 'handlers': { 'console': { 'level': 'DEBUG', 'class': 'logging.StreamHandler', 'formatter': 'standard' }, – Speedy99 Mar 30 '16 at 00:16
1

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.

Community
  • 1
  • 1
Kedar
  • 1,648
  • 10
  • 20
  • 2
    This is correct but there's a new logger: `django.server` that can be used. https://docs.djangoproject.com/en/1.11/topics/logging/#django-server – elnygren Jul 27 '17 at 09:09