infront-logger 1.1.10 → 1.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.MD CHANGED
@@ -142,6 +142,9 @@ Make sure to use before defining schemas;
142
142
  - success(req, res, body)
143
143
  - error(err)
144
144
 
145
+ #### Options
146
+ - maxBodyLength - -1 = unlimited, default: 128
147
+
145
148
  ### FastifyLogger (extends BaseLogger)
146
149
  #### Methods
147
150
  - request(req)
@@ -150,7 +153,10 @@ Make sure to use before defining schemas;
150
153
  - success(req, res, body)
151
154
  - error(err)
152
155
 
153
- ## options
156
+ #### Options
157
+ - maxBodyLength - -1 = unlimited, default: 128
158
+
159
+ ## Options
154
160
 
155
161
  - dirname - The directory in which the logs will be created (default: "logs")
156
162
  - levels - An object of "level name : hierarchical value"
@@ -193,14 +193,12 @@ function getZoneJsOriginalValue(target, name) {
193
193
  return original;
194
194
  }
195
195
  var __spreadArray = function(to, from, pack) {
196
- if (pack || arguments.length === 2)
197
- for (var i = 0, l = from.length, ar; i < l; i++) {
198
- if (ar || !(i in from)) {
199
- if (!ar)
200
- ar = Array.prototype.slice.call(from, 0, i);
201
- ar[i] = from[i];
202
- }
196
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
197
+ if (ar || !(i in from)) {
198
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
199
+ ar[i] = from[i];
203
200
  }
201
+ }
204
202
  return to.concat(ar || Array.prototype.slice.call(from));
205
203
  };
206
204
  var onMonitorErrorCollected;
@@ -313,8 +311,6 @@ function mergeObservables() {
313
311
  });
314
312
  }
315
313
  function throttle(fn, wait, options) {
316
- var needLeadingExecution = options && options.leading !== void 0 ? options.leading : true;
317
- var needTrailingExecution = options && options.trailing !== void 0 ? options.trailing : true;
318
314
  var inWaitPeriod = false;
319
315
  var pendingExecutionWithParameters;
320
316
  var pendingTimeoutId;
@@ -328,14 +324,12 @@ function throttle(fn, wait, options) {
328
324
  pendingExecutionWithParameters = parameters;
329
325
  return;
330
326
  }
331
- if (needLeadingExecution) {
327
+ {
332
328
  fn.apply(void 0, parameters);
333
- } else {
334
- pendingExecutionWithParameters = parameters;
335
329
  }
336
330
  inWaitPeriod = true;
337
331
  pendingTimeoutId = setTimeout(function() {
338
- if (needTrailingExecution && pendingExecutionWithParameters) {
332
+ if (pendingExecutionWithParameters) {
339
333
  fn.apply(void 0, pendingExecutionWithParameters);
340
334
  }
341
335
  inWaitPeriod = false;
@@ -385,9 +379,6 @@ function findCommaSeparatedValues(rawString) {
385
379
  return result;
386
380
  }
387
381
  function safeTruncate(candidate, length, suffix) {
388
- if (suffix === void 0) {
389
- suffix = "";
390
- }
391
382
  var lastChar = candidate.charCodeAt(length - 1);
392
383
  var isLastCharSurrogatePair = lastChar >= 55296 && lastChar <= 56319;
393
384
  var correctedLength = isLastCharSurrogatePair ? length + 1 : length;
@@ -3192,7 +3183,7 @@ function readBytesFromStream(stream, callback, options) {
3192
3183
  onDone();
3193
3184
  return;
3194
3185
  }
3195
- if (options.collectStreamBody) {
3186
+ {
3196
3187
  chunks.push(result.value);
3197
3188
  }
3198
3189
  readBytesCount += result.value.length;
@@ -3213,7 +3204,7 @@ function readBytesFromStream(stream, callback, options) {
3213
3204
  );
3214
3205
  var bytes;
3215
3206
  var limitExceeded;
3216
- if (options.collectStreamBody) {
3207
+ {
3217
3208
  var completeBuffer_1;
3218
3209
  if (chunks.length === 1) {
3219
3210
  completeBuffer_1 = chunks[0];
@@ -3282,12 +3273,8 @@ var StatusType = {
3282
3273
  var STATUS_PRIORITIES = (_a$3 = {}, _a$3[StatusType.ok] = 0, _a$3[StatusType.debug] = 1, _a$3[StatusType.info] = 2, _a$3[StatusType.notice] = 4, _a$3[StatusType.warn] = 5, _a$3[StatusType.error] = 6, _a$3[StatusType.critical] = 7, _a$3[StatusType.alert] = 8, _a$3[StatusType.emerg] = 9, _a$3);
3283
3274
  var __decorate = function(decorators, target, key, desc) {
3284
3275
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3285
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3286
- r = Reflect.decorate(decorators, target, key, desc);
3287
- else
3288
- for (var i = decorators.length - 1; i >= 0; i--)
3289
- if (d = decorators[i])
3290
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3276
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3277
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3291
3278
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3292
3279
  };
3293
3280
  var HandlerType = {
@@ -4145,7 +4132,19 @@ class DatadogLogger {
4145
4132
  if (!options.clientToken) {
4146
4133
  throw new Error('Please provide "clientToken" for your Datadog account');
4147
4134
  }
4148
- datadogLogs.init({ ...DEFAULTS, ...options });
4135
+ let { exclude = [], ...ddOptions } = options;
4136
+ datadogLogs.init({
4137
+ ...DEFAULTS,
4138
+ ...ddOptions,
4139
+ beforeSend: (log) => {
4140
+ try {
4141
+ if (exclude.some((string) => log && log.message && log.message.toLowerCase().includes(string.toLowerCase()))) {
4142
+ return false;
4143
+ }
4144
+ } catch (err) {
4145
+ }
4146
+ }
4147
+ });
4149
4148
  this.options = options;
4150
4149
  this.logger = datadogLogs.logger;
4151
4150
  this.ctx = {};
@@ -197,14 +197,12 @@
197
197
  return original;
198
198
  }
199
199
  var __spreadArray = function(to, from, pack) {
200
- if (pack || arguments.length === 2)
201
- for (var i = 0, l = from.length, ar; i < l; i++) {
202
- if (ar || !(i in from)) {
203
- if (!ar)
204
- ar = Array.prototype.slice.call(from, 0, i);
205
- ar[i] = from[i];
206
- }
200
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
201
+ if (ar || !(i in from)) {
202
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
203
+ ar[i] = from[i];
207
204
  }
205
+ }
208
206
  return to.concat(ar || Array.prototype.slice.call(from));
209
207
  };
210
208
  var onMonitorErrorCollected;
@@ -317,8 +315,6 @@
317
315
  });
318
316
  }
319
317
  function throttle(fn, wait, options) {
320
- var needLeadingExecution = options && options.leading !== void 0 ? options.leading : true;
321
- var needTrailingExecution = options && options.trailing !== void 0 ? options.trailing : true;
322
318
  var inWaitPeriod = false;
323
319
  var pendingExecutionWithParameters;
324
320
  var pendingTimeoutId;
@@ -332,14 +328,12 @@
332
328
  pendingExecutionWithParameters = parameters;
333
329
  return;
334
330
  }
335
- if (needLeadingExecution) {
331
+ {
336
332
  fn.apply(void 0, parameters);
337
- } else {
338
- pendingExecutionWithParameters = parameters;
339
333
  }
340
334
  inWaitPeriod = true;
341
335
  pendingTimeoutId = setTimeout(function() {
342
- if (needTrailingExecution && pendingExecutionWithParameters) {
336
+ if (pendingExecutionWithParameters) {
343
337
  fn.apply(void 0, pendingExecutionWithParameters);
344
338
  }
345
339
  inWaitPeriod = false;
@@ -389,9 +383,6 @@
389
383
  return result;
390
384
  }
391
385
  function safeTruncate(candidate, length, suffix) {
392
- if (suffix === void 0) {
393
- suffix = "";
394
- }
395
386
  var lastChar = candidate.charCodeAt(length - 1);
396
387
  var isLastCharSurrogatePair = lastChar >= 55296 && lastChar <= 56319;
397
388
  var correctedLength = isLastCharSurrogatePair ? length + 1 : length;
@@ -3196,7 +3187,7 @@
3196
3187
  onDone();
3197
3188
  return;
3198
3189
  }
3199
- if (options.collectStreamBody) {
3190
+ {
3200
3191
  chunks.push(result.value);
3201
3192
  }
3202
3193
  readBytesCount += result.value.length;
@@ -3217,7 +3208,7 @@
3217
3208
  );
3218
3209
  var bytes;
3219
3210
  var limitExceeded;
3220
- if (options.collectStreamBody) {
3211
+ {
3221
3212
  var completeBuffer_1;
3222
3213
  if (chunks.length === 1) {
3223
3214
  completeBuffer_1 = chunks[0];
@@ -3286,12 +3277,8 @@
3286
3277
  var STATUS_PRIORITIES = (_a$3 = {}, _a$3[StatusType.ok] = 0, _a$3[StatusType.debug] = 1, _a$3[StatusType.info] = 2, _a$3[StatusType.notice] = 4, _a$3[StatusType.warn] = 5, _a$3[StatusType.error] = 6, _a$3[StatusType.critical] = 7, _a$3[StatusType.alert] = 8, _a$3[StatusType.emerg] = 9, _a$3);
3287
3278
  var __decorate = function(decorators, target, key, desc) {
3288
3279
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3289
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3290
- r = Reflect.decorate(decorators, target, key, desc);
3291
- else
3292
- for (var i = decorators.length - 1; i >= 0; i--)
3293
- if (d = decorators[i])
3294
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3280
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3281
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3295
3282
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3296
3283
  };
3297
3284
  var HandlerType = {
@@ -4149,7 +4136,19 @@
4149
4136
  if (!options.clientToken) {
4150
4137
  throw new Error('Please provide "clientToken" for your Datadog account');
4151
4138
  }
4152
- datadogLogs.init({ ...DEFAULTS, ...options });
4139
+ let { exclude = [], ...ddOptions } = options;
4140
+ datadogLogs.init({
4141
+ ...DEFAULTS,
4142
+ ...ddOptions,
4143
+ beforeSend: (log) => {
4144
+ try {
4145
+ if (exclude.some((string) => log && log.message && log.message.toLowerCase().includes(string.toLowerCase()))) {
4146
+ return false;
4147
+ }
4148
+ } catch (err) {
4149
+ }
4150
+ }
4151
+ });
4153
4152
  this.options = options;
4154
4153
  this.logger = datadogLogs.logger;
4155
4154
  this.ctx = {};
package/dist/index.es.js CHANGED
@@ -102,10 +102,8 @@ function createTransport(options) {
102
102
  class Logger {
103
103
  constructor(options = {}) {
104
104
  this.options = { ...OPTIONS$1, ...options };
105
- if (!this.options.filename.includes("."))
106
- this.options.filename += ".log";
107
- if (!this.options.errorFilename.includes("."))
108
- this.options.errorFilename += ".log";
105
+ if (!this.options.filename.includes(".")) this.options.filename += ".log";
106
+ if (!this.options.errorFilename.includes(".")) this.options.errorFilename += ".log";
109
107
  let trans = [];
110
108
  let exceptionHandlers = [new transports.Console({
111
109
  format: getFormatter("console", this.options)
@@ -270,13 +268,11 @@ class BaseLogger {
270
268
  this.ctx.profiler[action] = Date.now() - startTime;
271
269
  }
272
270
  this.ctx.profiler.totalTime = Date.now() - this.absaluteStartTime;
273
- if (!options.continue)
274
- this.startTime = Date.now();
271
+ if (!options.continue) this.startTime = Date.now();
275
272
  return this;
276
273
  }
277
274
  _stopMemProfile() {
278
- if (this.memProfileInterval)
279
- clearInterval(this.memProfileInterval);
275
+ if (this.memProfileInterval) clearInterval(this.memProfileInterval);
280
276
  }
281
277
  profileMem(options = {}) {
282
278
  this.ctx.maxMemory = this.ctx.maxMemory || 0;
@@ -344,7 +340,7 @@ class HTTPLogger extends BaseLogger {
344
340
  this.ctx.response = {
345
341
  headers: omit$1(res.getHeaders(), "set-cookie", "x-powered-by"),
346
342
  statusCode: res.statusCode,
347
- body: trim$1(body, MAX_BODY_LENGTH$1)
343
+ body: this.options.maxBodyLength <= 0 ? body : trim$1(body, this.options.maxBodyLength || MAX_BODY_LENGTH$1)
348
344
  };
349
345
  this.ctx.responseTimeMs = Date.now() - this.startTime;
350
346
  this.ctx.responseSizeBytes = this.data ? JSON.stringify(this.data).length : 0;
@@ -362,12 +358,9 @@ class HTTPLogger extends BaseLogger {
362
358
  return `${method} ${url} ${statusCode} ${responseTimeMs} ${responseSize} ${ip} ${remoteAddress} ${msg || ""}`;
363
359
  }
364
360
  success(req, res, body) {
365
- if (req)
366
- this.request(req);
367
- if (res)
368
- this.response(res);
369
- if (body)
370
- this.body(body);
361
+ if (req) this.request(req);
362
+ if (res) this.response(res);
363
+ if (body) this.body(body);
371
364
  this._prepare();
372
365
  super.info(this._message());
373
366
  }
@@ -437,8 +430,7 @@ class MongooseLogger extends BaseLogger {
437
430
  this.ctx.resultLength = Array.isArray(res) ? res.length : res ? 1 : 0;
438
431
  } catch (err) {
439
432
  }
440
- if (!this.options.logRes)
441
- return this;
433
+ if (!this.options.logRes) return this;
442
434
  if (Array.isArray(res)) {
443
435
  this.ctx.documentCount = res.length;
444
436
  } else if (this.ctx.resultSizeBytes < this.options.maxResBytes) {
@@ -451,8 +443,7 @@ class MongooseLogger extends BaseLogger {
451
443
  }
452
444
  async function postHook(target, res) {
453
445
  var _a, _b, _c, _d, _e, _f, _g;
454
- if ((_a = target == null ? void 0 : target.options) == null ? void 0 : _a.explain)
455
- return;
446
+ if ((_a = target == null ? void 0 : target.options) == null ? void 0 : _a.explain) return;
456
447
  const op = target.constructor.name === "Aggregate" ? "aggregate" : target.op || target.$op;
457
448
  const collection = ((_b = target == null ? void 0 : target._collection) == null ? void 0 : _b.collectionName) || ((_c = target == null ? void 0 : target.collection) == null ? void 0 : _c.name) || ((_e = (_d = target == null ? void 0 : target._model) == null ? void 0 : _d.collection) == null ? void 0 : _e.collectionName);
458
449
  if (!op || !collection) {
@@ -586,12 +577,9 @@ class FastifyLogger extends BaseLogger {
586
577
  return this.req.ip || this.req._remoteAddress || void 0;
587
578
  }
588
579
  success(req, res, body) {
589
- if (req)
590
- this.request(req);
591
- if (res)
592
- this.response(res);
593
- if (body)
594
- this.body(body);
580
+ if (req) this.request(req);
581
+ if (res) this.response(res);
582
+ if (body) this.body(body);
595
583
  this._prepare();
596
584
  super.info(this._message());
597
585
  }
package/dist/index.umd.js CHANGED
@@ -106,10 +106,8 @@
106
106
  class Logger {
107
107
  constructor(options = {}) {
108
108
  this.options = { ...OPTIONS$1, ...options };
109
- if (!this.options.filename.includes("."))
110
- this.options.filename += ".log";
111
- if (!this.options.errorFilename.includes("."))
112
- this.options.errorFilename += ".log";
109
+ if (!this.options.filename.includes(".")) this.options.filename += ".log";
110
+ if (!this.options.errorFilename.includes(".")) this.options.errorFilename += ".log";
113
111
  let trans = [];
114
112
  let exceptionHandlers = [new transports.Console({
115
113
  format: getFormatter("console", this.options)
@@ -274,13 +272,11 @@
274
272
  this.ctx.profiler[action] = Date.now() - startTime;
275
273
  }
276
274
  this.ctx.profiler.totalTime = Date.now() - this.absaluteStartTime;
277
- if (!options.continue)
278
- this.startTime = Date.now();
275
+ if (!options.continue) this.startTime = Date.now();
279
276
  return this;
280
277
  }
281
278
  _stopMemProfile() {
282
- if (this.memProfileInterval)
283
- clearInterval(this.memProfileInterval);
279
+ if (this.memProfileInterval) clearInterval(this.memProfileInterval);
284
280
  }
285
281
  profileMem(options = {}) {
286
282
  this.ctx.maxMemory = this.ctx.maxMemory || 0;
@@ -348,7 +344,7 @@
348
344
  this.ctx.response = {
349
345
  headers: omit$1(res.getHeaders(), "set-cookie", "x-powered-by"),
350
346
  statusCode: res.statusCode,
351
- body: trim$1(body, MAX_BODY_LENGTH$1)
347
+ body: this.options.maxBodyLength <= 0 ? body : trim$1(body, this.options.maxBodyLength || MAX_BODY_LENGTH$1)
352
348
  };
353
349
  this.ctx.responseTimeMs = Date.now() - this.startTime;
354
350
  this.ctx.responseSizeBytes = this.data ? JSON.stringify(this.data).length : 0;
@@ -366,12 +362,9 @@
366
362
  return `${method} ${url} ${statusCode} ${responseTimeMs} ${responseSize} ${ip} ${remoteAddress} ${msg || ""}`;
367
363
  }
368
364
  success(req, res, body) {
369
- if (req)
370
- this.request(req);
371
- if (res)
372
- this.response(res);
373
- if (body)
374
- this.body(body);
365
+ if (req) this.request(req);
366
+ if (res) this.response(res);
367
+ if (body) this.body(body);
375
368
  this._prepare();
376
369
  super.info(this._message());
377
370
  }
@@ -441,8 +434,7 @@
441
434
  this.ctx.resultLength = Array.isArray(res) ? res.length : res ? 1 : 0;
442
435
  } catch (err) {
443
436
  }
444
- if (!this.options.logRes)
445
- return this;
437
+ if (!this.options.logRes) return this;
446
438
  if (Array.isArray(res)) {
447
439
  this.ctx.documentCount = res.length;
448
440
  } else if (this.ctx.resultSizeBytes < this.options.maxResBytes) {
@@ -455,8 +447,7 @@
455
447
  }
456
448
  async function postHook(target, res) {
457
449
  var _a, _b, _c, _d, _e, _f, _g;
458
- if ((_a = target == null ? void 0 : target.options) == null ? void 0 : _a.explain)
459
- return;
450
+ if ((_a = target == null ? void 0 : target.options) == null ? void 0 : _a.explain) return;
460
451
  const op = target.constructor.name === "Aggregate" ? "aggregate" : target.op || target.$op;
461
452
  const collection = ((_b = target == null ? void 0 : target._collection) == null ? void 0 : _b.collectionName) || ((_c = target == null ? void 0 : target.collection) == null ? void 0 : _c.name) || ((_e = (_d = target == null ? void 0 : target._model) == null ? void 0 : _d.collection) == null ? void 0 : _e.collectionName);
462
453
  if (!op || !collection) {
@@ -590,12 +581,9 @@
590
581
  return this.req.ip || this.req._remoteAddress || void 0;
591
582
  }
592
583
  success(req, res, body) {
593
- if (req)
594
- this.request(req);
595
- if (res)
596
- this.response(res);
597
- if (body)
598
- this.body(body);
584
+ if (req) this.request(req);
585
+ if (res) this.response(res);
586
+ if (body) this.body(body);
599
587
  this._prepare();
600
588
  super.info(this._message());
601
589
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "infront-logger",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "description": "",
5
5
  "files": [
6
6
  "dist"