| 6 | const HEADER_FOOTER_BYTES = (new safeGlobalBlob([HEADER])).size + (new safeGlobalBlob([FOOTER])).size; |
| 7 | |
| 8 | class SeqLogger { |
| 9 | constructor(config) { |
| 10 | let dflt = { |
| 11 | serverUrl: 'http://localhost:5341', |
| 12 | apiKey: null, |
| 13 | maxBatchingTime: 2000, |
| 14 | eventSizeLimit: 256 * 1024, |
| 15 | batchSizeLimit: 1024 * 1024, |
| 16 | requestTimeout: 30000, |
| 17 | maxRetries: 5, |
| 18 | retryDelay: 5000, |
| 19 | onError: e => { |
| 20 | console.error("[seq]", e); |
| 21 | } |
| 22 | }; |
| 23 | let cfg = config || dflt; |
| 24 | var serverUrl = cfg.serverUrl || dflt.serverUrl; |
| 25 | if (!serverUrl.endsWith('/')) { |
| 26 | serverUrl += '/'; |
| 27 | } |
| 28 | this._endpoint = serverUrl + 'api/events/raw'; |
| 29 | this._apiKey = cfg.apiKey || dflt.apiKey; |
| 30 | this._maxBatchingTime = cfg.maxBatchingTime || dflt.maxBatchingTime; |
| 31 | this._eventSizeLimit = cfg.eventSizeLimit || dflt.eventSizeLimit; |
| 32 | this._batchSizeLimit = cfg.batchSizeLimit || dflt.batchSizeLimit; |
| 33 | this._requestTimeout = cfg.requestTimeout || dflt.requestTimeout; |
| 34 | this._onError = cfg.onError || dflt.onError; |
| 35 | this._maxRetries = cfg.maxRetries || dflt.maxRetries; |
| 36 | this._retryDelay = cfg.retryDelay || dflt.retryDelay; |
| 37 | |
| 38 | this._queue = []; |
| 39 | this._timer = null; |
| 40 | this._closed = false; |
| 41 | this._activeShipper = null; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Flush events queued at the time of the call, and wait for pending writes to complete regardless of configured batching/timers. |
| 46 | * @returns {Promise<boolean>} |
| 47 | */ |
| 48 | flush() { |
| 49 | return this._ship(); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Flush then destroy connections, close the logger, destroying timers and other resources. |
| 54 | * @returns {Promise<void>} |
| 55 | */ |
| 56 | close() { |
| 57 | if (this._closed) { |
| 58 | throw new Error('The logger has already been closed.'); |
| 59 | } |
| 60 | |
| 61 | this._closed = true; |
| 62 | this._clearTimer(); |
| 63 | return this.flush(); |
| 64 | } |
| 65 |
nothing calls this directly
no outgoing calls
no test coverage detected