Tuesday, May 10, 2011

Logging view exceptions: A tip and a question.

Tip part 1:

I just learned about the awesome logging.exception function today.
Instead of a logger.error or logging.debug, you can call
logging.exception (if you're in the "except" of a try/except block), and
it will automatically include the stack trace. This is super-helpful,
especially now that Django has more integrated logging in 1.3.

Tip part 2:

If you're doing AJAX and have 500 errors, this makes it really easy to
know exactly what broke. Add a decorator that does this logging and
decorate your views with it. Example: http://dpaste.com/hold/540815/

Question:

Assuming performance won't be a major concern, I'd like to decorate all
my views automatically. My first thought was middleware, but since it
handles requests and responses, I don't think it's the right layer. Does
anyone know the best place for automatically decorating all views with a
specific decorator?

Thanks,
Shawn

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate