【问题标题】:Write the contents of node debug log to file将节点调试日志的内容写入文件
【发布时间】:2015-04-04 15:30:23
【问题描述】:

我可以将此输出的内容写入文件吗?我正在使用debug 模块来记录消息,我希望能够将它们通过管道传输到文件中。但是它没有按预期工作。

$ DEBUG=* node -e 'var debug = require("debug")("test"); debug("hello world")'
    test hello world +0ms
$ DEBUG=* node -e 'var debug = require("debug")("test"); debug("hello world")' > temp.txt
    test hello world +0ms

刚刚试了一下,也没有收到任何输出。

$ { DEBUG=* node -e "var debug = require('debug')('test'); debug('hello world')"; } >temp.txt
    test hello world +0ms

【问题讨论】:

  • 我遇到了同样的问题,只有一处不同。如果我使用 node 运行我的应用程序 - 一切都很酷并且调试工作正常,但是如果我使用 nodemon 运行我的应用程序 - 我会收到完全相同的错误。我创建了显示错误的小型演示 repo github.com/speedster-kiev/debug-nodemon-error。有什么建议吗?

标签: node.js bash pipe stdout


【解决方案1】:
  1. 确保您运行的是最新版本的debug。
  2. 您需要使用DEBUG_FD=3 env 标志以及3> 来管道

这是一个例子。

$ DEBUG_FD=3 DEBUG=foo node -e "require('debug')('foo')('hello')" 3> foo.txt

来自回购的问题request/question: is there a way for debug to log to a file?

【讨论】:

    【解决方案2】:

    使用DEBUG_FD=3 对我不起作用。

    对我有用的选项是将2> 用于管道:

    DEBUG=* node --inspect=0.0.0.0:9229 . 2> log.txt
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-19
      • 1970-01-01
      • 1970-01-01
      • 2012-04-06
      • 2023-03-31
      • 1970-01-01
      • 2020-02-21
      相关资源
      最近更新 更多