Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Python exception errors in Heroku log

I have a Heroku application written i Python. When it fails it does not log anything, but just stops code execution at the location of failure (it does not execute print statements just below) and then continues to run as nothing happens.

How can I display exception errors and traceback in the log? Is the behaviour different when exceptions are raised using the raise statement?

I have set the following in the config file:

DEBUG = True
PRESERVE_CONTEXT_ON_EXCEPTION = True

Tried with and without PRESERVE_CONTEXT_ON_EXCEPTION.

like image 869
elgehelge Avatar asked Jan 03 '15 11:01

elgehelge


People also ask

How do I see 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.


1 Answers

It depends on your environment.

Try to add these lines:

stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.INFO)
app.logger.addHandler(stream_handler)

Also, if you run the server with Gunicorn, you should add --log-level debug to your Procfile

like image 57
Itay Kahana Avatar answered Sep 20 '22 11:09

Itay Kahana