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-05-23 22:31:38 +00:00
|
|
|
app.on('ready', async () => {
|
|
|
|
await netLog.startLogging('/path/to/net-log')
|
2018-10-04 18:08:56 +00:00
|
|
|
// 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.
|
|
|
|
|
2019-05-23 22:31:38 +00:00
|
|
|
Returns `Promise<void>` - resolves when the net log has begun recording.
|
|
|
|
|
2018-06-19 01:45:58 +00:00
|
|
|
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.
|
|
|
|
|
2019-05-23 22:31:38 +00:00
|
|
|
### `netLog.currentlyLoggingPath` **Deprecated**
|
2018-06-19 01:45:58 +00:00
|
|
|
|
|
|
|
A `String` property that returns the path to the current log file.
|