将节点调试日志内容写入文件

问题描述 投票:0回答:2

我可以将此输出的内容写入文件吗?我正在使用 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.js bash pipe stdout
2个回答
4
投票
  1. 确保您运行最新版本的
    debug
  2. 您需要使用
    DEBUG_FD=3
    env 标志以及
    3>
    进行管道传输

这是一个例子。

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

来自存储库的问题请求/问题:有没有办法让调试记录到文件?


4
投票

使用

DEBUG_FD=3
对我来说不起作用。

对我有用的选项是使用

2>
进行管道传输:

DEBUG=* node --inspect=0.0.0.0:9229 . 2> log.txt
© www.soinside.com 2019 - 2024. All rights reserved.