Skip to main content

netLog

Logging network events for a session.正在记录会话的网络事件。

Process:进程:Main

const { netLog } = require('electron')

app.whenReady().then(async () => {
await netLog.startLogging('/path/to/net-log')
// After some network events
const path = await netLog.stopLogging()
console.log('Net-logs written to', path)
})

See --log-net-log to log network events throughout the app's lifecycle.请参阅--log-net-log,以记录应用程序整个生命周期中的网络事件。

Note: All methods unless specified can only be used after the ready event of the app module gets emitted.除非指定,否则所有方法只能在发出app模块的ready事件后使用。

Methods方法

netLog.startLogging(path[, options])

  • path string - File path to record network logs.记录网络日志的文件路径。
  • options Object (optional)
    • captureMode string (optional) - What kinds of data should be captured. By default, only metadata about requests will be captured. 应该捕获哪些类型的数据。默认情况下,将只捕获有关请求的元数据。Setting this to includeSensitive will include cookies and authentication data. 将其设置为includeSensitive将包括cookie和身份验证数据。Setting it to everything will include all bytes transferred on sockets. 将其设置为everything将包括套接字上传输的所有字节。Can be default, includeSensitive or everything.可以是defaultincludeSensitiveeverything
    • maxFileSize number (optional) - When the log grows beyond this size, logging will automatically stop. 当日志增长超过此大小时,日志记录将自动停止。Defaults to unlimited.默认为无限制。

Returns返回Promise<void> - resolves when the net log has begun recording.在网络日志开始记录时解析。

Starts recording network events to path.开始将网络事件记录到path

netLog.stopLogging()

Returns返回Promise<void> - resolves when the net log has been flushed to disk.当网络日志被刷新到磁盘时解析。

Stops recording network events. 停止记录网络事件。If not called, net logging will automatically end when app quits.如果未调用,则当应用程序退出时,网络日志记录将自动结束。

Properties属性

netLog.currentlyLogging Readonly

A boolean property that indicates whether network logs are currently being recorded.一个boolean属性,指示当前是否正在记录网络日志。