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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With