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
|
|
|
|
2020-02-03 22:43:22 +00:00
|
|
|
app.whenReady().then(async () => {
|
2019-05-23 22:31:38 +00:00
|
|
|
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
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2019-10-04 17:49:09 +00:00
|
|
|
See [`--log-net-log`](command-line-switches.md#--log-net-logpath) to log network events throughout the app's lifecycle.
|
2018-06-19 01:45:58 +00:00
|
|
|
|
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
|
|
|
|
|
2019-07-25 23:06:39 +00:00
|
|
|
### `netLog.startLogging(path[, options])`
|
2018-06-19 01:45:58 +00:00
|
|
|
|
|
|
|
* `path` String - File path to record network logs.
|
2019-07-25 23:06:39 +00:00
|
|
|
* `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. Setting
|
|
|
|
it to `everything` will include all bytes transferred on sockets. Can be
|
|
|
|
`default`, `includeSensitive` or `everything`.
|
|
|
|
* `maxFileSize` Number (optional) - When the log grows beyond this size,
|
|
|
|
logging will automatically stop. Defaults to unlimited.
|
2018-06-19 01:45:58 +00:00
|
|
|
|
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()`
|
|
|
|
|
2020-03-18 23:46:05 +00:00
|
|
|
Returns `Promise<void>` - resolves when the net log has been flushed to disk.
|
2019-02-19 10:48:27 +00:00
|
|
|
|
|
|
|
Stops recording network events. If not called, net logging will automatically end when app quits.
|
|
|
|
|
2018-06-19 01:45:58 +00:00
|
|
|
## Properties
|
|
|
|
|
2019-07-26 23:12:59 +00:00
|
|
|
### `netLog.currentlyLogging` _Readonly_
|
2018-06-19 01:45:58 +00:00
|
|
|
|
2020-03-18 23:46:05 +00:00
|
|
|
A `Boolean` property that indicates whether network logs are currently being recorded.
|