Log errors to file

25 views
Skip to first unread message

Jonathan Hayward

unread,
Jul 7, 2010, 5:35:35 PM7/7/10
to django...@googlegroups.com
I'm working on a view made to output JSON for Ajax use. My log has:

[07/Jul/2010 17:47:13] "POST /ajax/login HTTP/1.1" 500 50678

That looks like Django gave a helpful and detailed stacktrace page, albeit to jQuery expecting JSON.

How can I ask Django to log uncaught exceptions to a file or equivalent? The test server has no MTA so I can't really ask it to email me exceptions.

TIA,
--
→ Jonathan Hayward, christos.jon...@gmail.com
→ An Orthodox Christian author: theology, literature, et cetera.
→ My award-winning collection is available for free reading online:
☩ I invite you to visit my main site at http://JonathansCorner.com/

elijah rutschman

unread,
Jul 7, 2010, 6:35:30 PM7/7/10
to django...@googlegroups.com
You could implement a middleware class with a process_exception
method. See: http://docs.djangoproject.com/en/dev/topics/http/middleware/#process_exception

-Elijah

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

Jonathan Hayward

unread,
Jul 7, 2010, 7:05:27 PM7/7/10
to django...@googlegroups.com
Thank you!

Brian Neal

unread,
Jul 7, 2010, 8:07:44 PM7/7/10
to Django users
On Jul 7, 4:35 pm, Jonathan Hayward
<christos.jonathan.hayw...@gmail.com> wrote:
> I'm working on a view made to output JSON for Ajax use. My log has:
>
> [07/Jul/2010 17:47:13] "POST /ajax/login HTTP/1.1" 500 50678
>
> That looks like Django gave a helpful and detailed stacktrace page, albeit
> to jQuery expecting JSON.

If there is a "human in the loop", you can use the Firebug extension
on Firefox to monitor requests and responses made via AJAX. I look at
Django 500 pages through Firebug all the time. ;-)

http://getfirebug.com/

Best,
BN

euan.g...@gmail.com

unread,
Jul 8, 2010, 5:34:11 AM7/8/10
to Django users
I have created a decorator for Django views which handles AJAX
tracebacks and sends the traceback back to the AJAX application as
JSON, e.g.

{'status':'error', 'message': <traceback goes here>}

It uses the traceback module to output the full traceback. Obviously
you need to have a handler that receives this data and displays in on
the page (although you can inspect it in firebug).

If you'd like the code for it, I can ask my company whether they'd be
happy with me publishing it.

Cheers, Euan

On Jul 7, 10:35 pm, Jonathan Hayward
<christos.jonathan.hayw...@gmail.com> wrote:
> I'm working on a view made to output JSON for Ajax use. My log has:
>
> [07/Jul/2010 17:47:13] "POST /ajax/login HTTP/1.1" 500 50678
>
> That looks like Django gave a helpful and detailed stacktrace page, albeit
> to jQuery expecting JSON.
>
> How can I ask Django to log uncaught exceptions to a file or equivalent? The
> test server has no MTA so I can't really ask it to email me exceptions.
>
> TIA,
> --
> → Jonathan Hayward, christos.jonathan.hayw...@gmail.com

Sævar Öfjörð

unread,
Jul 9, 2010, 8:33:08 AM7/9/10
to Django users
That's something that would be nice to have as a snippet on
djangosnippets.org!

On Jul 8, 11:34 am, "euan.godd...@googlemail.com"

Jonathan Hayward

unread,
Jul 14, 2010, 3:20:05 PM7/14/10
to django...@googlegroups.com
I'm interested and I doubt I'm the only one.

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




--
→ Jonathan Hayward, christos.jon...@gmail.com
Reply all
Reply to author
Forward
0 new messages