netLog
记录会话的网络事件。
¥Logging network events for a session.
进程:主进程
¥Process: Main
const { app, 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)
})
请参阅 --log-net-log 以在应用的整个生命周期中记录网络事件。
¥See --log-net-log to log network events throughout the app's lifecycle.
[!NOTE] 除非另有说明,否则所有方法只能在
app模块的ready事件触发后使用。¥[!NOTE] All methods unless specified can only be used after the
readyevent of theappmodule gets emitted.
方法
¥Methods
netLog.startLogging(path[, options])
-
path字符串 - 记录网络日志的文件路径。¥
pathstring - File path to record network logs.
返回 Promise<void> - 当网络日志开始记录时解决。
¥Returns Promise<void> - resolves when the net log has begun recording.
开始将网络事件记录到 path。
¥Starts recording network events to path.
netLog.stopLogging()
返回 Promise<void> - 当网络日志已刷新到磁盘时解决。
¥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 只读
¥netLog.currentlyLogging Readonly
boolean 属性,指示当前是否正在记录网络日志。
¥A boolean property that indicates whether network logs are currently being recorded.