Skip to content

Commit

Permalink
Add #onReportLogs(logs) (#64)
Browse files Browse the repository at this point in the history
* add `#onReportLogs(logs)`

Overwrite this function to handle logs yourself in addition to the
 Saturn pipeline.

* use parameter instead

* Update src/client.js

---------

Co-authored-by: Hannah Howard <hannah@hannahhoward.net>
  • Loading branch information
juliangruber and hannahhoward authored Mar 27, 2024
1 parent 864daa8 commit e6578e0
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class Saturn {
* @param {number} [config.fallbackLimit]
* @param {boolean} [config.experimental]
* @param {string} [config.format]
* @param {Function} [config.onReportLogs]
* @param {import('./storage/index.js').Storage} [config.storage]
*/
constructor (config = {}) {
Expand All @@ -61,6 +62,7 @@ export class Saturn {
this._monitorPerformanceBuffer()
}
this.storage = this.config.storage || memoryStorage()
this.onReportLogs = this.config.onReportLogs || ((_logs) => {})
this.loadNodesPromise = this.config.experimental ? this._loadNodes(this.config) : null
this.authLimiter = pLimit(1)
}
Expand Down Expand Up @@ -488,14 +490,14 @@ export class Saturn {
body: JSON.stringify({ bandwidthLogs, logSender: this.config.logSender })
}
)
this.onReportLogs(bandwidthLogs)
} catch (e) {
console.log(e)
throw e
} finally {
this.logs = []
this._clearPerformanceBuffer()
}

}

/**
Expand Down

0 comments on commit e6578e0

Please sign in to comment.