配置


🌐 Configuration

报告生成的附加运行时配置可以通过 process.report 的以下属性进行设置:

🌐 Additional runtime configuration of report generation is available via the following properties of process.report:

reportOnFatalError 在为 true 时会在发生致命错误时触发诊断报告。默认值为 false。

reportOnSignal 在为 true 时会在信号发生时触发诊断报告。Windows 不支持此功能。默认值为 false。

reportOnUncaughtException 在未捕获的异常发生时触发诊断报告,当设置为 true 时生效。默认值为 false。

signal 指定将用于拦截报告生成的外部触发的 POSIX 信号标识符。默认值为 'SIGUSR2'。

filename 指定文件系统中输出文件的名称。stdout 和 stderr 有特殊意义。使用它们将导致报告写入关联的标准流。在使用标准流的情况下,会忽略 directory 的值。不支持 URL。默认情况下,文件名为包含时间戳、进程 ID 和序列号的复合文件名。

directory 指定报告将被写入的文件系统目录。不支持 URL。默认情况下为 Node.js 进程的当前工作目录。

excludeNetwork 会将 header.networkInterfaces 从诊断报告中排除。

// Trigger report only on uncaught exceptions.
process.report.reportOnFatalError = false;
process.report.reportOnSignal = false;
process.report.reportOnUncaughtException = true;

// Trigger report for both internal errors as well as external signal.
process.report.reportOnFatalError = true;
process.report.reportOnSignal = true;
process.report.reportOnUncaughtException = false;

// Change the default signal to 'SIGQUIT' and enable it.
process.report.reportOnFatalError = false;
process.report.reportOnUncaughtException = false;
process.report.reportOnSignal = true;
process.report.signal = 'SIGQUIT';

// Disable network interfaces reporting
process.report.excludeNetwork = true; 

模块初始化时的配置也可以通过环境变量进行:

🌐 Configuration on module initialization is also available via environment variables:

NODE_OPTIONS="--report-uncaught-exception \
  --report-on-fatalerror --report-on-signal \
  --report-signal=SIGUSR2  --report-filename=./report.json \
  --report-directory=/home/nodeuser" 

具体的 API 文档可以在 process API documentation 部分找到。

🌐 Specific API documentation can be found under process API documentation section.