Heroku日志Django项目缺少错误 [英] Heroku logs for Django projects missing errors

查看:130
本文介绍了Heroku日志Django项目缺少错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Heroku上运行一个简单的Django项目。它有效,但是如果我收到服务器错误,它不会在日志中给我任何细节。这使得错误难以应付。



现在我已经设置了一个登台服务器,它有同样的问题 - 页面失败,我没有得到关于为什么的任何反馈。



$ heroku日志



...

  2012-08-08T13:55:58 + 00:00 app [web.1]:开发服务器正在http://0.0.0.0:59048 / 
2012-08-08T13:55:59 + 00:00 heroku [web.1]:状态从开始上升到
2012-08-08T13:56:01 + 00:00 heroku [路由器]: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.1500 27
2012-08-08T13:56:02 + 00:00 heroku [路由器]: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 [路由器]: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/8 / 2012 14:56:09]GET / admin HTTP / 1.1301 0
2012-08-08T13:56:10 + 00:00 heroku [路由器]: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 / 2012 14:56:10]GET / admin / HTTP / 1.1500 27
2012-08-08T13:56:10 + 00:00 heroku [路由器]:GET [xxx] .herokuapp.com / favicon .ico dyno = web.1 queue = 0 wait = 0ms service = 6ms status = 500 bytes = 27

您可以看到,页面返回为500,但是我没有得到任何堆栈跟踪信息或类似的信息。



可能的问题可以表示为:'开发服务器正在运行...' - 这是什么意思,它是否影响错误记录?



此外,我使用'500.html'模板文件来定义一个自定义的500错误页面。这可能会隐藏错误吗?真的不应该。



或者我需要在Heroku的Django上找另一个地方登录日志吗?



谢谢!

解决方案

看起来这只是一个问题,这个期望是由Heroku下的Django将像Rails一样工作。愚蠢的我。

对于从一个框架/语言转移到另一个框架/语言时遇到这个问题的任何人:




  • 当调试关闭时,Django使用标准的Python记录器来处理代码中的错误。

  • 在settings.py的底部有一个默认设置当有错误时,电子邮件给站点管理员。尼斯。它需要在settings.py中的ADMINS变量中的一组电子邮件地址才能正常工作。

  • 默认情况下,错误发送到STDERR而不是STDOUT,因此它们不会在日志中显示。这可以很明显地改变。如果您想要这样做,请尝试:



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



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!

解决方案

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/

这篇关于Heroku日志Django项目缺少错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆