2013-10-12 26 views
6

我正在爲Heroku託管使用Flask和工頭。我開始我的本地服務器輸入foreman start。我的問題是,我想看看我的代碼產生的日誌錯誤消息,但我還沒有找到正確的方法來做到這一點。如何使用Flask和工頭(heroku)記錄錯誤消息?

我試着用一些代碼,我喜歡這樣的瓶文檔中找到,但它不工作之一:

import logging 
from FileHandler import FileHandler 
file_handler = FileHandler("log.txt") 
file_handler.setLevel(logging.WARNING) 
app.logger.addHandler(file_handler) 

任何想法如何能夠與foreman start運行時燒瓶讀解錯誤信息?

回答

8

我有一個類似的問題 - 最終問題不是與福爾曼,而是使用更新版本的Gunicorn,默認情況下禁用控制檯日誌記錄(http://gunicorn-docs.readthedocs.org/en/latest/faq.html#why-i-don-t-see-any-logs-in-the-console)。

更改我的procfile來自:

web: gunicorn app:app 

web: gunicorn --log-file=- app:app 

解決這個問題對我來說。

+0

我的上帝(或GORD,我應該說?) - 我一直在尋找兩天這個答案。謝謝。 – Zack