当前位置: 首页 > 文档资料 > Electron 中文文档 >

netLog

优质
小牛编辑
161浏览
2023-12-01

Logging network events for a session.

进程:主进程

const { netLog } = require('electron')
app.on('ready', async function () {
  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 记录应用生命周期的网络事件。

注意: 除了指定的方法, 其他方法只能在 app 模块的 ready 事件被触发后使用。

Logging network events for a session.

Process: Main

const { netLog } = require('electron')
app.on('ready', async function () {
  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.

Note: All methods unless specified can only be used after the ready event of the app module gets emitted.

方法

Methods

netLog.startLogging(path)

  • path String - 记录网络日志的文件路径。

开始记录网络事件日志到 path

netLog.startLogging(path)

  • path String - File path to record network logs.

Starts recording network events to path.

netLog.stopLogging([callback])

  • callback Function (可选)

    • path String - 记录网络日志的文件路径。

停止网络事件日志的记录。 如果未被调用,net 记录将自动结束当 app 退出的时候。

即将弃用

netLog.stopLogging([callback])

  • callback Function (optional)

    • path String - File path to which network logs were recorded.

Stops recording network events. If not called, net logging will automatically end when app quits.

Deprecated Soon

netLog.stopLogging()

Returns Promise<String> - resolves with a file path to which network logs were recorded.

停止网络事件日志的记录。 如果未被调用,net 记录将自动结束当 app 退出的时候。

netLog.stopLogging()

Returns Promise<String> - resolves with a file path to which network logs were recorded.

Stops recording network events. If not called, net logging will automatically end when app quits.

属性

Properties

netLog.currentlyLogging

Boolean 类型的属性,指示网络日志是否被记录。

netLog.currentlyLogging

A Boolean property that indicates whether network logs are recorded.

netLog.currentlyLoggingPath

String 类型的属性,返回当前的日志文件路径。

netLog.currentlyLoggingPath

A String property that returns the path to the current log file.