Flask 应用程序在本地运行良好,在 Heroku 上抛出 500(在某些路由上)并且没有日志
Flask app runs fine locally, throws 500 on Heroku (on some routes) & no logs
我有一个在本地运行良好的 Flask 应用程序。我把它推到了这个 Heroku URL:
https://secret-sierra-6425.herokuapp.com/
登陆页面有效,这意味着“/”路由代码有效。
但是当我尝试访问其他资源时,它会抛出 500 错误并且我在日志中看不到任何有用的信息:
2015-04-06T08:17:29.687713+00:00 app[web.1]: [2015-04-06 08:17:29 +0000] [3] [INFO] Shutting down: Master
2015-04-06T08:17:30.397309+00:00 app[web.1]: [2015-04-06 08:17:30 +0000] [3] [INFO] Starting gunicorn 19.3.0
2015-04-06T08:17:30.484520+00:00 app[web.1]: [2015-04-06 08:17:30 +0000] [10] [INFO] Booting worker with pid: 10
2015-04-06T08:17:30.398009+00:00 app[web.1]: [2015-04-06 08:17:30 +0000] [3] [INFO] Listening at: http://0.0.0.0:18230 (3)
2015-04-06T08:17:30.398107+00:00 app[web.1]: [2015-04-06 08:17:30 +0000] [3] [INFO] Using worker: sync
2015-04-06T08:17:30.407696+00:00 app[web.1]: [2015-04-06 08:17:30 +0000] [9] [INFO] Booting worker with pid: 9
2015-04-06T08:17:30.682319+00:00 heroku[web.1]: State changed from starting to up
2015-04-06T08:17:30.618107+00:00 heroku[web.1]: Process exited with status 0
2015-04-06T08:18:23.485060+00:00 heroku[router]: at=info method=GET path="/" host=secret-sierra-6425.herokuapp.com request_id=cbdfada9-8b28-4150-a7c0-eddc458658d9 fwd="23.252.53.59" dyno=web.1 connect=1ms service=2ms status=200 bytes=186
2015-04-06T08:18:35.630070+00:00 heroku[router]: at=info method=POST path="/messages" host=secret-sierra-6425.herokuapp.com request_id=aaecbfbd-57b5-49eb-aee0-ad450ba67e36 fwd="23.252.53.59" dyno=web.1 connect=1ms service=19ms status=500 bytes=456
这是启动我的应用程序的代码:
if __name__ == '__main__':
app.debug = True #Only for development, not prod
app.logger.addHandler(logging.StreamHandler(sys.stdout))
app.logger.setLevel(logging.ERROR)
app.run()
过程文件:
web: gunicorn mailr:app --log-file=-
worker: python worker.py
我的应用程序也使用了 Redis 队列。我添加了 RedisToGo 插件。仍然没有运气。
任何人都可以帮我找到一种显示日志的方法,以便我可以调试出现的问题吗?
\
编辑:
也试过把开头改成这个,还是不行:
app.debug = True #Only for development, not prod
file_handler = StreamHandler()
app.logger.setLevel(logging.DEBUG) # set the desired logging level here
app.logger.addHandler(file_handler)
app.run()
知道了。记录日志的代码应该在main
之外
我有一个在本地运行良好的 Flask 应用程序。我把它推到了这个 Heroku URL: https://secret-sierra-6425.herokuapp.com/
登陆页面有效,这意味着“/”路由代码有效。 但是当我尝试访问其他资源时,它会抛出 500 错误并且我在日志中看不到任何有用的信息:
2015-04-06T08:17:29.687713+00:00 app[web.1]: [2015-04-06 08:17:29 +0000] [3] [INFO] Shutting down: Master
2015-04-06T08:17:30.397309+00:00 app[web.1]: [2015-04-06 08:17:30 +0000] [3] [INFO] Starting gunicorn 19.3.0
2015-04-06T08:17:30.484520+00:00 app[web.1]: [2015-04-06 08:17:30 +0000] [10] [INFO] Booting worker with pid: 10
2015-04-06T08:17:30.398009+00:00 app[web.1]: [2015-04-06 08:17:30 +0000] [3] [INFO] Listening at: http://0.0.0.0:18230 (3)
2015-04-06T08:17:30.398107+00:00 app[web.1]: [2015-04-06 08:17:30 +0000] [3] [INFO] Using worker: sync
2015-04-06T08:17:30.407696+00:00 app[web.1]: [2015-04-06 08:17:30 +0000] [9] [INFO] Booting worker with pid: 9
2015-04-06T08:17:30.682319+00:00 heroku[web.1]: State changed from starting to up
2015-04-06T08:17:30.618107+00:00 heroku[web.1]: Process exited with status 0
2015-04-06T08:18:23.485060+00:00 heroku[router]: at=info method=GET path="/" host=secret-sierra-6425.herokuapp.com request_id=cbdfada9-8b28-4150-a7c0-eddc458658d9 fwd="23.252.53.59" dyno=web.1 connect=1ms service=2ms status=200 bytes=186
2015-04-06T08:18:35.630070+00:00 heroku[router]: at=info method=POST path="/messages" host=secret-sierra-6425.herokuapp.com request_id=aaecbfbd-57b5-49eb-aee0-ad450ba67e36 fwd="23.252.53.59" dyno=web.1 connect=1ms service=19ms status=500 bytes=456
这是启动我的应用程序的代码:
if __name__ == '__main__':
app.debug = True #Only for development, not prod
app.logger.addHandler(logging.StreamHandler(sys.stdout))
app.logger.setLevel(logging.ERROR)
app.run()
过程文件:
web: gunicorn mailr:app --log-file=-
worker: python worker.py
我的应用程序也使用了 Redis 队列。我添加了 RedisToGo 插件。仍然没有运气。
任何人都可以帮我找到一种显示日志的方法,以便我可以调试出现的问题吗? \
编辑:
也试过把开头改成这个,还是不行:
app.debug = True #Only for development, not prod
file_handler = StreamHandler()
app.logger.setLevel(logging.DEBUG) # set the desired logging level here
app.logger.addHandler(file_handler)
app.run()
知道了。记录日志的代码应该在main
之外