Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku logs for Django projects missing errors

I'm running a simple Django project on Heroku. It works, but if I get a server error it doesn't give me any details in the logs. This makes errors incredibly hard to deal with.

Now I've set up a staging server and it has the same problem - the pages are failing and I don't get any feedback as to why.

$ heroku logs

...

2012-08-08T13:55:58+00:00 app[web.1]: Development server is running at http://0.0.0.0:59048/
2012-08-08T13:55:59+00:00 heroku[web.1]: State changed from starting to up
2012-08-08T13:56:01+00:00 heroku[router]: GET [xxx].herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=22ms status=500 bytes=27
2012-08-08T13:56:01+00:00 app[web.1]: [08/Aug/2012 14:56:01] "GET / HTTP/1.1" 500 27
2012-08-08T13:56:02+00:00 heroku[router]: GET [xxx].herokuapp.com/favicon.ico dyno=web.1 queue=0 wait=0ms service=6ms status=500 bytes=27
2012-08-08T13:56:09+00:00 heroku[router]: GET[xxx].herokuapp.com/admin dyno=web.1 queue=0 wait=0ms service=2ms status=301 bytes=0
2012-08-08T13:56:09+00:00 app[web.1]: [08/Aug/2012 14:56:09] "GET /admin HTTP/1.1" 301 0
2012-08-08T13:56:10+00:00 heroku[router]: GET [xxx].herokuapp.com/admin/ dyno=web.1 queue=0 wait=0ms service=224ms status=500 bytes=27
2012-08-08T13:56:10+00:00 app[web.1]: [08/Aug/2012 14:56:10] "GET /admin/ HTTP/1.1" 500 27
2012-08-08T13:56:10+00:00 heroku[router]: GET [xxx].herokuapp.com/favicon.ico dyno=web.1 queue=0 wait=0ms service=6ms status=500 bytes=27

As you can see, pages are returning as 500, but I'm not getting any stack trace information or similar.

Possible problems could be indicated by: 'Development server is running at...' - what does this mean and is it affecting error logging?

Also, I'm using a '500.html' template file to define a custom 500 error page. Could this be hiding errors somehow? It really shouldn't.

Or do I need to be looking in another place for logs with Django on Heroku?

Thanks!

like image 362
dark fader Avatar asked Aug 08 '12 14:08

dark fader


People also ask

How do I get heroku error logs?

You can view logs with the Heroku CLI, the dashboard, your logging add-on, or in your log drain. You can't view logs for apps in Shield spaces with Private Space Logging enabled. Retrieve logs from your log drain instead.

What is the purpose of the command heroku logs?

The Heroku logs –tail option is the real-time tail parameter. Its purpose is to display current log entries while keeping the session alive for additional entries to stream while the app continues to run in production.


1 Answers

Looks like it was simply a problem caused by an expectation that Django under Heroku would work like Rails. Silly me.

For anyone else suffering this problem when moving from one framework/language to another:

  • When debug is off, Django uses the standard Python logger to handle errors in the code.
  • There is a default set-up at the bottom of settings.py which emails the site admins when there are errors. Nice. It needs an array of email addresses in the ADMINS variable in settings.py to work.
  • Errors are sent, by default, to STDERR instead of STDOUT, so they won't show in the logs. This can be changed apparently. Try here if you want this behaviour:

    http://codeinthehole.com/writing/console-logging-to-stdout-in-django/

like image 147
dark fader Avatar answered Sep 21 '22 20:09

dark fader