我在heroku this blog中设置了一个超级简单的node.js任务。一切似乎都有效,但当我使用heroku logs --tail
时,我的console.log语句不会显示在控制台中。
我的任务如下:
#!/usr/bin/env node
var firebase = require('firebase')
console.log('I have loaded firebase');
我知道它正在运行,因为我在pacakages.json中没有firebase npm包并且得到了预期的错误。一旦解决了,一切似乎运行正常,但我没有从我的console.log行获得任何输出。 = [
我用heroku run reconcileTasks
执行了任务,并在日志尾中获得以下输出:
2016-02-25T21:47:00.483677+00:00 heroku[api]: Starting process with command `reconcileTasks` by somecoolfella@geemail.com
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 :(得分:1)
在安排任务运行过夜后,我发现日志显示了我期待的消息。显然,console.log转到用户将要查看它的上下文。当我通过heroku run
命令手动运行它时,它会显示在我工作的控制台中,但是当heroku调度程序运行它时,它会显示在日志中。这是一个非常酷的魔术。 =]
2016-02-26T05:30:16.396497+00:00 heroku[api]: Starting process with command `reconcileTasks` by scheduler@addons.heroku.com
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