2018-06-19 01:45:58 +00:00
|
|
|
# netLog
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
> Logging network events for a session.
|
2018-06-19 01:45:58 +00:00
|
|
|
|
|
|
|
Process: [Main](../glossary.md#main-process)
|
|
|
|
|
|
|
|
```javascript
|
2018-09-13 16:10:51 +00:00
|
|
|
const { netLog } = require('electron')
|
2018-10-04 18:08:56 +00:00
|
|
|
|
2019-02-19 10:48:27 +00:00
|
|
|
app.on('ready', async function () {
|
2018-10-04 18:08:56 +00:00
|
|
|
netLog.startLogging('/path/to/net-log')
|
|
|
|
// After some network events
|
2019-02-19 10:48:27 +00:00
|
|
|
const path = await netLog.stopLogging()
|
|
|
|
console.log('Net-logs written to', path)
|
2018-06-19 01:45:58 +00:00
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
See [`--log-net-log`](chrome-command-line-switches.md#--log-net-logpath) to log network events throughout the app's lifecycle.
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
**Note:** All methods unless specified can only be used after the `ready` event
|
|
|
|
of the `app` module gets emitted.
|
|
|
|
|
2018-06-19 01:45:58 +00:00
|
|
|
## Methods
|
|
|
|
|
|
|
|
### `netLog.startLogging(path)`
|
|
|
|
|
|
|
|
* `path` String - File path to record network logs.
|
|
|
|
|
|
|
|
Starts recording network events to `path`.
|
|
|
|
|
2019-02-19 10:48:27 +00:00
|
|
|
### `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.
|
|
|
|
|
2018-06-19 01:45:58 +00:00
|
|
|
## Properties
|
|
|
|
|
|
|
|
### `netLog.currentlyLogging`
|
|
|
|
|
|
|
|
A `Boolean` property that indicates whether network logs are recorded.
|
|
|
|
|
|
|
|
### `netLog.currentlyLoggingPath`
|
|
|
|
|
|
|
|
A `String` property that returns the path to the current log file.
|