I am working with Flask and Foreman for the Heroku hosting. I start my local server typing foreman start
. My issue is that I want to see the log error messages that my code produces but I haven't found the right way to do it.
I tried with some code that I found in the Flask documentation like this, but it doesn't work either:
import logging
from FileHandler import FileHandler
file_handler = FileHandler("log.txt")
file_handler.setLevel(logging.WARNING)
app.logger.addHandler(file_handler)
Any idea how to be able to read de error messages when running Flask with foreman start
?
I had a similar problem - in the end the issue wasn't with Foreman, but with using a newer version of Gunicorn where console logging was disabled by default ( http://gunicorn-docs.readthedocs.org/en/latest/faq.html#why-i-don-t-see-any-logs-in-the-console ).
Changing my procfile from:
web: gunicorn app:app
to
web: gunicorn --log-file=- app:app
solved the issue for me.
Heroku and Foreman expect your logs to go to stdout
or stderr
, not to a file. See the Heroku documentation on logging .
For a Python app you can use the logging.StreamHandler class, which logs to stderr
by default.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.