Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log error messages with Flask and foreman (heroku)?

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?

like image 594
Xar Avatar asked Oct 12 '13 18:10

Xar


1 Answers

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.

like image 170
Gord Stephen Avatar answered Sep 30 '22 21:09

Gord Stephen