MCPcopy Create free account
hub / github.com/datalust/seq-logging / _dequeBatch

Method _dequeBatch

seq_logger.js:190–233  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

188 }
189
190 _dequeBatch() {
191 var bytes = HEADER_FOOTER_BYTES;
192 let batch = [];
193 var i = 0;
194 var delimSize = 0;
195 while (i < this._queue.length) {
196 let next = this._queue[i];
197 let json;
198 try {
199 json = JSON.stringify(next);
200 } catch (e) {
201 const cleaned = removeCirculars(next);
202 json = JSON.stringify(cleaned);
203 // Log that this event to be able to detect circular structures
204 // using same timestamp as cleaned event to make finding it easier
205 this.emit({
206 timestamp: cleaned.Timestamp,
207 level: "Error",
208 messageTemplate: "[seq] Circular structure found"
209 });
210 }
211 var jsonLen = new safeGlobalBlob([json]).size;
212 if (jsonLen > this._eventSizeLimit) {
213 this._onError("[seq] Event body is larger than " + this._eventSizeLimit + " bytes: " + json);
214 this._queue[i] = next = this._eventTooLargeErrorEvent(next);
215 json = JSON.stringify(next);
216 jsonLen = new safeGlobalBlob([json]).size;
217 }
218
219 // Always try to send a batch of at least one event, even if the batch size is
220 // tiny.
221 if (i !== 0 && bytes + jsonLen + delimSize > this._batchSizeLimit) {
222 break;
223 }
224
225 i = i + 1;
226 bytes += jsonLen + delimSize;
227 delimSize = 1; // ","
228 batch.push(json);
229 }
230
231 this._queue.splice(0, i);
232 return {batch, bytes};
233 }
234
235 _httpOrNetworkError(res) {
236 const networkErrors = ['ECONNRESET', 'ENOTFOUND', 'ESOCKETTIMEDOUT', 'ETIMEDOUT', 'ECONNREFUSED', 'EHOSTUNREACH', 'EPIPE', 'EAI_AGAIN', 'EBUSY'];

Callers 1

_sendBatchMethod · 0.95

Calls 3

emitMethod · 0.95
removeCircularsFunction · 0.85

Tested by

no test coverage detected