诊断通道


【Diagnostics Channel】

源代码: lib/diagnostics_channel.js

node:diagnostics_channel 模块提供了一个 API,用于创建命名通道,以便为诊断目的报告任意消息数据。

【The node:diagnostics_channel module provides an API to create named channels to report arbitrary message data for diagnostics purposes.】

可以使用以下方式访问它:

【It can be accessed using:】

import diagnostics_channel from 'node:diagnostics_channel';const diagnostics_channel = require('node:diagnostics_channel');

模块编写者如果想要报告诊断信息,通常会创建一个或多个顶层通道来传递信息。通道也可以在运行时获取,但不推荐这样做,因为这样会增加额外的开销。通道可以为了方便而导出,但只要名称已知,就可以在任何地方获取。

【It is intended that a module writer wanting to report diagnostics messages will create one or many top-level channels to report messages through. Channels may also be acquired at runtime but it is not encouraged due to the additional overhead of doing so. Channels may be exported for convenience, but as long as the name is known it can be acquired anywhere.】

如果你打算让你的模块生成供他人使用的诊断数据,建议你附上用于哪些命名通道的文档,以及消息数据的结构。通道名称通常应包含模块名称,以避免与其他模块的数据发生冲突。

【If you intend for your module to produce diagnostics data for others to consume it is recommended that you include documentation of what named channels are used along with the shape of the message data. Channel names should generally include the module name to avoid collisions with data from other modules.】