如何在没有环境变量的情况下启用NODE_DEBUG?

Rya*_*oss 10 node.js node-debugger aws-lambda

我正在尝试在AWS Lambda环境(Node.js 4.3)中运行时调试node.js https库环境中似乎是套接字错误的内容.此问题仅在间歇性地发生且仅在重负载下发生.我的团队已经能够通过负载测试一致地重现该问题,并且我们希望从https模块启用调试日志记录.

我在节点文档中发现我可以通过设置NODE_DEBUG=https环境变量来启用调试日志记录.但是,我不相信我可以设置环境变量:如何在AWS Lambda上使用环境变量?.此外,我无法更改Lambda用于调用我的函数的命令行.

是否有另一种方法可以创建与设置相同的调试日志记录NODE_DEBUG

rob*_*lep 5

这是一个猴子补丁:

const util    = require('util');
let debuglog  = util.debuglog;
util.debuglog = set => {
  if (set === 'https') {
    let pid = process.pid;
    return function() {
      let msg = util.format.apply(util, arguments);
      console.error('%s %d: %s', set, pid, msg);
    }
  }
  return debuglog(set);
}

// This has to occur _after_ the code above:
const https = require('https');
Run Code Online (Sandbox Code Playgroud)

它基本上启用了debug日志记录,https而不论$NODE_DEBUG。易于重新编写以适用于经Node v4和v6测试的任何模块。