【问题标题】:Why aren't my node.js heroku task console.log statements displayed in the heroku log?为什么我的 node.js heroku 任务 console.log 语句没有显示在 heroku 日志中?
【发布时间】:2016-02-26 21:40:26
【问题描述】:

根据this blog,我在heroku 中设置了一个超级简单的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

【问题讨论】:

    标签: node.js heroku


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2018-04-11
      • 2015-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-07
      相关资源
      最近更新 更多