Speedy99
Speedy99

Reputation: 1751

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?

Upvotes: 6

Views: 6632

Answers (3)

elnygren
elnygren

Reputation: 5345

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

Upvotes: 4

Kedar
Kedar

Reputation: 1698

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.

Upvotes: 1

Roshan
Roshan

Reputation: 1937

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.

Upvotes: 1

Related Questions