nodejs使用pm2和debug,'debug'模块将所有日志输出都输出到stderr,为什么?

时间:2014-12-16 12:38:59

标签: node.js debugging logging pm2

pm2 -version:0.12.1;debug -version:2.1.0

代码:

 debug("Send data to client success! length " + buf.length+" Bytes!");

pm2 logs:

[1_control-15 (err)] Tue, 16 Dec 2014 12:36:50 GMT [1_control] Client.ts Send data to client success! length 100 Bytes!

[1_control-15 (err)] Tue, 16 Dec 2014 12:36:50 GMT [1_control]n Client.ts Send data to client success! length 135 Bytes!

请帮忙。

3 个答案:

答案 0 :(得分:1)

不确定问题是否仍然相关,但正如official documentation所说,您可以像这样覆盖此行为:

  var debug = require('debug');
  var error = debug('app:error');

  // by default stderr is used 
  error('goes to stderr!');

  var log = debug('app:log');
  // set this namespace to log via console.log 
  log.log = console.log.bind(console); // don't forget to bind to console! 
  log('goes to stdout');
  error('still goes to stderr!');

  // set all output to go via console.info 
  // overrides all per-namespace log settings 
  debug.log = console.info.bind(console);
  error('now goes to stdout via console.info');
  log('still goes to stdout, but via console.info now');

`

答案 1 :(得分:0)

调试模块从2. *版本设置所有日志到stderr,1。*版本将没事

答案 2 :(得分:0)

设置DEBUG_FD = 1可以将输出流更改为process.stdout



DEBUG_FD=1 node index.js