2016-02-26 48 views
0

我已經有一個超級簡單的node.js任務在heroku中設置爲this blog。似乎一切正常,但是當我使用heroku logs --tail時,console.log語句不顯示在控制檯中。爲什麼我的node.js heroku任務console.log語句顯示在heroku日誌中?

我的任務是這樣的:

#!/usr/bin/env node 

var firebase = require('firebase') 
console.log('I have loaded firebase'); 

我知道它的運行,因爲我沒有在pacakages.json的火力NPM包,並得到了預期的錯誤。一旦解決,一切似乎運行良好,但我沒有從我的console.log行輸出。 = [

我執行任務與heroku run reconcileTasks並獲得在日誌尾部下面的輸出:

2016-02-25T21:47:00.483677+00:00 heroku[api]: Starting process with command `reconcileTasks` by [email protected] 
2016-02-25T21:47:01.648730+00:00 heroku[run.2829]: Awaiting client 
2016-02-25T21:47:01.687472+00:00 heroku[run.2829]: Starting process with command `reconcileTasks` 
2016-02-25T21:47:01.945501+00:00 heroku[run.2829]: State changed from starting to up 
2016-02-25T21:47:03.964158+00:00 heroku[run.2829]: Process exited with status 0 
2016-02-25T21:47:03.991854+00:00 heroku[run.2829]: State changed from up to complete 

回答

0

已預約任務運行過夜後,我發現了日誌顯示我的消息期待。顯然,console.log會轉到用戶將要看到的上下文。當我通過heroku run命令手動運行它時,它顯示在我工作的控制檯中,但是當heroku調度程序運行它時,它會顯示在日誌中。這是一些非常酷的魔法。 =]

2016-02-26T05:30:16.396497+00:00 heroku[api]: Starting process with command `reconcileTasks` by [email protected] 
2016-02-26T05:30:17.623505+00:00 heroku[scheduler.7098]: Starting process with command `reconcileTasks` 
2016-02-26T05:30:18.316360+00:00 heroku[scheduler.7098]: State changed from starting to up 
2016-02-26T05:30:19.866568+00:00 app[scheduler.7098]: I have loaded firebase 
2016-02-26T05:30:20.819687+00:00 heroku[scheduler.7098]: State changed from up to complete 
2016-02-26T05:30:20.805612+00:00 heroku[scheduler.7098]: Process exited with status 0 
相關問題