Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print a stack trace to stdout on errors in Django while using manage.py runserver

Tags:

I did some searching, but I'm wondering if anyone has a snippet of a logging configuration to get Django to just output a stack trace to stdout (so I can see it in the Terminal window) when it encounters an error during a request. This is specifically for local development/debugging and mainly for when I do AJAX post requests and I have to look at the HTML in Firebug to figure out what line the error occurred on.

like image 584
Bialecki Avatar asked May 04 '11 15:05

Bialecki


1 Answers

Another method is with LOGGING. Specifically you get a stacktrace when running ./manage.py runserver by adding the following to the settings.py file:

LOGGING = {
    'version': 1,
    'handlers': {
        'console':{
            'level':'DEBUG',
            'class':'logging.StreamHandler',
        },
    },
    'loggers': {
        'django.request': {
            'handlers':['console'],
            'propagate': True,
            'level':'DEBUG',
        }
    },
}

This syntax comes from the Django documentation Configuring Logging and can be further modified to increase or decrease the amount of console-logging.

Also the 5XX responses are raised as ERROR messages and 4XX responses are raised as WARNING messages.

Note that this question & answer has a 2013 duplicate here.

like image 67
Mike Biglan MS Avatar answered Oct 13 '22 00:10

Mike Biglan MS