How can I get uncaught exceptions to appear in the Django log
Asked Answered
S

1

5

When there are uncaught exceptions in my Django project the log only shows a simple "HTTP 500" message. The HTTP response will contain the full stack trace as HTML but this is not very useful when I am developing web services not being consumed by a web browser. How can I get the full stack trace of uncaught exceptions to appear in the Django log?

I have tried installing custom middleware with a "process_exception" method and custom signals handler for the "got_request_exception" event but neither of these handlers ever got invoked.

I am using Django 1.6.1 and Tastypie 0.11.0 and I'm running in debug mode.

Souther answered 17/1, 2014 at 2:40 Comment(0)
W
8

In your django settings set:

DEBUG_PROPAGATE_EXCEPTIONS = True
TASTYPIE_FULL_DEBUG = True

Setting both of these options will allow Tastypie exceptions to propagate upwards.

https://docs.djangoproject.com/en/3.2/ref/settings/#debug-propagate-exceptions
http://django-tastypie.readthedocs.org/en/latest/settings.html#tastypie-full-debug

Wahhabi answered 17/1, 2014 at 2:47 Comment(2)
is it good practice to enable these options in production too?Stereo
No its not good practice, those settings should only be used in development. When DEBUG is False (i.e in production), Django will email the users listed in the ADMINS setting whenever your code raises an unhandled exception. However, a better way to handle exception monitoring in production is to use the likes of rollbar.com or getsentry.com.Wahhabi

© 2022 - 2024 — McMap. All rights reserved.