@webex/plugin-logger 3.0.0-beta.2 → 3.0.0-beta.200

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.
@@ -45,9 +45,10 @@ describe('plugin-logger', () => {
45
45
  beforeEach(() => {
46
46
  webex = new MockWebex({
47
47
  children: {
48
- logger: Logger
49
- }
48
+ logger: Logger,
49
+ },
50
50
  });
51
+ webex.logger.config.historyLength = 10000;
51
52
  });
52
53
 
53
54
  const fallbacks = {
@@ -55,7 +56,7 @@ describe('plugin-logger', () => {
55
56
  warn: ['error', 'log'],
56
57
  info: ['log'],
57
58
  debug: ['info', 'log'],
58
- trace: ['debug', 'info', 'log']
59
+ trace: ['debug', 'info', 'log'],
59
60
  };
60
61
 
61
62
  function impl(level) {
@@ -154,12 +155,12 @@ describe('plugin-logger', () => {
154
155
  const error = new WebexHttpError({
155
156
  statusCode: 500,
156
157
  body: {
157
- error: 'Internal Error'
158
+ error: 'Internal Error',
158
159
  },
159
160
  options: {
160
161
  service: '',
161
- headers: {}
162
- }
162
+ headers: {},
163
+ },
163
164
  });
164
165
 
165
166
  webex.logger.log(error);
@@ -172,12 +173,12 @@ describe('plugin-logger', () => {
172
173
  const error = new WebexHttpError({
173
174
  statusCode: 500,
174
175
  body: {
175
- error: 'Internal Error'
176
+ error: 'Internal Error',
176
177
  },
177
178
  options: {
178
179
  service: '',
179
- headers: {}
180
- }
180
+ headers: {},
181
+ },
181
182
  });
182
183
 
183
184
  webex.logger.log(error);
@@ -196,60 +197,186 @@ describe('plugin-logger', () => {
196
197
  function testLevels(logType, logConfigSetting) {
197
198
  /* eslint max-statements: [0] */
198
199
  webex.logger.config[logConfigSetting] = 'trace';
199
- assert.isTrue(webex.logger.shouldPrint('error', logType), 'it prints `error` logs when the level is `trace`');
200
- assert.isTrue(webex.logger.shouldPrint('warn', logType), 'it prints `warn` logs when the level is `trace`');
201
- assert.isTrue(webex.logger.shouldPrint('log', logType), 'it prints `log` logs when the level is `trace`');
202
- assert.isTrue(webex.logger.shouldPrint('info', logType), 'it prints `info` logs when the level is `trace`');
203
- assert.isTrue(webex.logger.shouldPrint('debug', logType), 'it prints `debug` logs when the level is `trace`');
204
- assert.isTrue(webex.logger.shouldPrint('trace', logType), 'it prints `trace` logs when the level is `trace`');
200
+ assert.isTrue(
201
+ webex.logger.shouldPrint('error', logType),
202
+ 'it prints `error` logs when the level is `trace`'
203
+ );
204
+ assert.isTrue(
205
+ webex.logger.shouldPrint('warn', logType),
206
+ 'it prints `warn` logs when the level is `trace`'
207
+ );
208
+ assert.isTrue(
209
+ webex.logger.shouldPrint('log', logType),
210
+ 'it prints `log` logs when the level is `trace`'
211
+ );
212
+ assert.isTrue(
213
+ webex.logger.shouldPrint('info', logType),
214
+ 'it prints `info` logs when the level is `trace`'
215
+ );
216
+ assert.isTrue(
217
+ webex.logger.shouldPrint('debug', logType),
218
+ 'it prints `debug` logs when the level is `trace`'
219
+ );
220
+ assert.isTrue(
221
+ webex.logger.shouldPrint('trace', logType),
222
+ 'it prints `trace` logs when the level is `trace`'
223
+ );
205
224
 
206
225
  webex.logger.config[logConfigSetting] = 'debug';
207
- assert.isTrue(webex.logger.shouldPrint('error', logType), 'it prints `error` logs when the level is `debug`');
208
- assert.isTrue(webex.logger.shouldPrint('warn', logType), 'it prints `warn` logs when the level is `debug`');
209
- assert.isTrue(webex.logger.shouldPrint('log', logType), 'it prints `log` logs when the level is `debug`');
210
- assert.isTrue(webex.logger.shouldPrint('info', logType), 'it prints `info` logs when the level is `debug`');
211
- assert.isTrue(webex.logger.shouldPrint('debug', logType), 'it prints `debug` logs when the level is `debug`');
212
- assert.isFalse(webex.logger.shouldPrint('trace', logType), 'it does not print `trace` logs when the level is `debug`');
226
+ assert.isTrue(
227
+ webex.logger.shouldPrint('error', logType),
228
+ 'it prints `error` logs when the level is `debug`'
229
+ );
230
+ assert.isTrue(
231
+ webex.logger.shouldPrint('warn', logType),
232
+ 'it prints `warn` logs when the level is `debug`'
233
+ );
234
+ assert.isTrue(
235
+ webex.logger.shouldPrint('log', logType),
236
+ 'it prints `log` logs when the level is `debug`'
237
+ );
238
+ assert.isTrue(
239
+ webex.logger.shouldPrint('info', logType),
240
+ 'it prints `info` logs when the level is `debug`'
241
+ );
242
+ assert.isTrue(
243
+ webex.logger.shouldPrint('debug', logType),
244
+ 'it prints `debug` logs when the level is `debug`'
245
+ );
246
+ assert.isFalse(
247
+ webex.logger.shouldPrint('trace', logType),
248
+ 'it does not print `trace` logs when the level is `debug`'
249
+ );
213
250
 
214
251
  webex.logger.config[logConfigSetting] = 'info';
215
- assert.isTrue(webex.logger.shouldPrint('error', logType), 'it prints `error` logs when the level is `info`');
216
- assert.isTrue(webex.logger.shouldPrint('warn', logType), 'it prints `warn` logs when the level is `info`');
217
- assert.isTrue(webex.logger.shouldPrint('log', logType), 'it prints `log` logs when the level is `info`');
218
- assert.isTrue(webex.logger.shouldPrint('info', logType), 'it prints `info` logs when the level is `info`');
219
- assert.isFalse(webex.logger.shouldPrint('debug', logType), 'it does not print `debug` logs when the level is `info`');
220
- assert.isFalse(webex.logger.shouldPrint('trace', logType), 'it does not print `trace` logs when the level is `info`');
252
+ assert.isTrue(
253
+ webex.logger.shouldPrint('error', logType),
254
+ 'it prints `error` logs when the level is `info`'
255
+ );
256
+ assert.isTrue(
257
+ webex.logger.shouldPrint('warn', logType),
258
+ 'it prints `warn` logs when the level is `info`'
259
+ );
260
+ assert.isTrue(
261
+ webex.logger.shouldPrint('log', logType),
262
+ 'it prints `log` logs when the level is `info`'
263
+ );
264
+ assert.isTrue(
265
+ webex.logger.shouldPrint('info', logType),
266
+ 'it prints `info` logs when the level is `info`'
267
+ );
268
+ assert.isFalse(
269
+ webex.logger.shouldPrint('debug', logType),
270
+ 'it does not print `debug` logs when the level is `info`'
271
+ );
272
+ assert.isFalse(
273
+ webex.logger.shouldPrint('trace', logType),
274
+ 'it does not print `trace` logs when the level is `info`'
275
+ );
221
276
 
222
277
  webex.logger.config[logConfigSetting] = 'log';
223
- assert.isTrue(webex.logger.shouldPrint('error', logType), 'it prints `error` logs when the level is `log`');
224
- assert.isTrue(webex.logger.shouldPrint('warn', logType), 'it prints `warn` logs when the level is `log`');
225
- assert.isTrue(webex.logger.shouldPrint('log', logType), 'it prints `log` logs when the level is `log`');
226
- assert.isFalse(webex.logger.shouldPrint('info', logType), 'it does not print `info` logs when the level is `log`');
227
- assert.isFalse(webex.logger.shouldPrint('debug', logType), 'it does not print `debug` logs when the level is `log`');
228
- assert.isFalse(webex.logger.shouldPrint('trace', logType), 'it does not print `trace` logs when the level is `log`');
278
+ assert.isTrue(
279
+ webex.logger.shouldPrint('error', logType),
280
+ 'it prints `error` logs when the level is `log`'
281
+ );
282
+ assert.isTrue(
283
+ webex.logger.shouldPrint('warn', logType),
284
+ 'it prints `warn` logs when the level is `log`'
285
+ );
286
+ assert.isTrue(
287
+ webex.logger.shouldPrint('log', logType),
288
+ 'it prints `log` logs when the level is `log`'
289
+ );
290
+ assert.isFalse(
291
+ webex.logger.shouldPrint('info', logType),
292
+ 'it does not print `info` logs when the level is `log`'
293
+ );
294
+ assert.isFalse(
295
+ webex.logger.shouldPrint('debug', logType),
296
+ 'it does not print `debug` logs when the level is `log`'
297
+ );
298
+ assert.isFalse(
299
+ webex.logger.shouldPrint('trace', logType),
300
+ 'it does not print `trace` logs when the level is `log`'
301
+ );
229
302
 
230
303
  webex.logger.config[logConfigSetting] = 'warn';
231
- assert.isTrue(webex.logger.shouldPrint('error', logType), 'it prints `error` logs when the level is `warn`');
232
- assert.isTrue(webex.logger.shouldPrint('warn', logType), 'it prints `warn` logs when the level is `warn`');
233
- assert.isFalse(webex.logger.shouldPrint('log', logType), 'it does not print `log` logs when the level is `warn`');
234
- assert.isFalse(webex.logger.shouldPrint('info', logType), 'it does not print `info` logs when the level is `warn`');
235
- assert.isFalse(webex.logger.shouldPrint('debug', logType), 'it does not print `debug` logs when the level is `warn`');
236
- assert.isFalse(webex.logger.shouldPrint('trace', logType), 'it does not print `trace` logs when the level is `warn`');
304
+ assert.isTrue(
305
+ webex.logger.shouldPrint('error', logType),
306
+ 'it prints `error` logs when the level is `warn`'
307
+ );
308
+ assert.isTrue(
309
+ webex.logger.shouldPrint('warn', logType),
310
+ 'it prints `warn` logs when the level is `warn`'
311
+ );
312
+ assert.isFalse(
313
+ webex.logger.shouldPrint('log', logType),
314
+ 'it does not print `log` logs when the level is `warn`'
315
+ );
316
+ assert.isFalse(
317
+ webex.logger.shouldPrint('info', logType),
318
+ 'it does not print `info` logs when the level is `warn`'
319
+ );
320
+ assert.isFalse(
321
+ webex.logger.shouldPrint('debug', logType),
322
+ 'it does not print `debug` logs when the level is `warn`'
323
+ );
324
+ assert.isFalse(
325
+ webex.logger.shouldPrint('trace', logType),
326
+ 'it does not print `trace` logs when the level is `warn`'
327
+ );
237
328
 
238
329
  webex.logger.config[logConfigSetting] = 'error';
239
- assert.isTrue(webex.logger.shouldPrint('error', logType), 'it prints `error` logs when the level is `error`');
240
- assert.isFalse(webex.logger.shouldPrint('warn', logType), 'it does not print `warn` logs when the level `error` is ');
241
- assert.isFalse(webex.logger.shouldPrint('log', logType), 'it does not print `log` logs when the level is `error`');
242
- assert.isFalse(webex.logger.shouldPrint('info', logType), 'it does not print `info` logs when the level is `error`');
243
- assert.isFalse(webex.logger.shouldPrint('debug', logType), 'it does not print `debug` logs when the level is `error`');
244
- assert.isFalse(webex.logger.shouldPrint('trace', logType), 'it does not print `trace` logs when the level is `error`');
330
+ assert.isTrue(
331
+ webex.logger.shouldPrint('error', logType),
332
+ 'it prints `error` logs when the level is `error`'
333
+ );
334
+ assert.isFalse(
335
+ webex.logger.shouldPrint('warn', logType),
336
+ 'it does not print `warn` logs when the level `error` is '
337
+ );
338
+ assert.isFalse(
339
+ webex.logger.shouldPrint('log', logType),
340
+ 'it does not print `log` logs when the level is `error`'
341
+ );
342
+ assert.isFalse(
343
+ webex.logger.shouldPrint('info', logType),
344
+ 'it does not print `info` logs when the level is `error`'
345
+ );
346
+ assert.isFalse(
347
+ webex.logger.shouldPrint('debug', logType),
348
+ 'it does not print `debug` logs when the level is `error`'
349
+ );
350
+ assert.isFalse(
351
+ webex.logger.shouldPrint('trace', logType),
352
+ 'it does not print `trace` logs when the level is `error`'
353
+ );
245
354
 
246
355
  webex.logger.config[logConfigSetting] = 'silent';
247
- assert.isFalse(webex.logger.shouldPrint('error', logType), 'it does not print `error` logs when the level is `silent`');
248
- assert.isFalse(webex.logger.shouldPrint('warn', logType), 'it does not print `warn` logs when the level is `silent`');
249
- assert.isFalse(webex.logger.shouldPrint('log', logType), 'it does not print `log` logs when the level is `silent`');
250
- assert.isFalse(webex.logger.shouldPrint('info', logType), 'it does not print `info` logs when the level is `silent`');
251
- assert.isFalse(webex.logger.shouldPrint('debug', logType), 'it does not print `debug` logs when the level is `silent`');
252
- assert.isFalse(webex.logger.shouldPrint('trace', logType), 'it does not print `trace` logs when the level is `silent`');
356
+ assert.isFalse(
357
+ webex.logger.shouldPrint('error', logType),
358
+ 'it does not print `error` logs when the level is `silent`'
359
+ );
360
+ assert.isFalse(
361
+ webex.logger.shouldPrint('warn', logType),
362
+ 'it does not print `warn` logs when the level is `silent`'
363
+ );
364
+ assert.isFalse(
365
+ webex.logger.shouldPrint('log', logType),
366
+ 'it does not print `log` logs when the level is `silent`'
367
+ );
368
+ assert.isFalse(
369
+ webex.logger.shouldPrint('info', logType),
370
+ 'it does not print `info` logs when the level is `silent`'
371
+ );
372
+ assert.isFalse(
373
+ webex.logger.shouldPrint('debug', logType),
374
+ 'it does not print `debug` logs when the level is `silent`'
375
+ );
376
+ assert.isFalse(
377
+ webex.logger.shouldPrint('trace', logType),
378
+ 'it does not print `trace` logs when the level is `silent`'
379
+ );
253
380
  }
254
381
 
255
382
  it('indicates whether or not the desired log should be printed at the current log level', () => {
@@ -310,20 +437,20 @@ describe('plugin-logger', () => {
310
437
  developer: {
311
438
  get() {
312
439
  return 'info';
313
- }
440
+ },
314
441
  },
315
442
  entitlement: {
316
443
  get() {
317
444
  return false;
318
- }
319
- }
320
- }
445
+ },
446
+ },
447
+ },
321
448
  };
322
449
  webex.logger.info('test');
323
450
  assert.called(console.info);
324
451
  });
325
452
 
326
- nodeOnly(it)('doesn\'t break if the feature toggle is set to an incorrect value', () => {
453
+ nodeOnly(it)("doesn't break if the feature toggle is set to an incorrect value", () => {
327
454
  assert.doesNotThrow(() => {
328
455
  assert.notCalled(console.info);
329
456
  webex.logger.info('test');
@@ -334,14 +461,14 @@ describe('plugin-logger', () => {
334
461
  developer: {
335
462
  get() {
336
463
  return 'not-a-log-method';
337
- }
464
+ },
338
465
  },
339
466
  entitlement: {
340
467
  get() {
341
468
  return false;
342
- }
343
- }
344
- }
469
+ },
470
+ },
471
+ },
345
472
  };
346
473
  webex.logger.info('test');
347
474
  assert.notCalled(console.info);
@@ -378,29 +505,30 @@ describe('plugin-logger', () => {
378
505
  });
379
506
  });
380
507
 
381
-
382
508
  describe('#filter', () => {
383
509
  it('redacts email addresses', () => {
384
510
  const message = {
385
- blarg: 'test@example.com'
511
+ blarg: 'test@example.com',
386
512
  };
387
513
 
388
- assert.deepEqual(webex.logger.filter(message), [{
389
- blarg: '[REDACTED]'
390
- }]);
514
+ assert.deepEqual(webex.logger.filter(message), [
515
+ {
516
+ blarg: '[REDACTED]',
517
+ },
518
+ ]);
391
519
  });
392
520
 
393
521
  it('strips auth headers from log output', () => {
394
522
  const msg = {
395
523
  headers: {
396
- authorization: 'Bearer'
524
+ authorization: 'Bearer',
397
525
  },
398
526
  options: {
399
527
  headers: {
400
528
  trackingid: '123',
401
- authorization: 'Bearer'
402
- }
403
- }
529
+ authorization: 'Bearer',
530
+ },
531
+ },
404
532
  };
405
533
 
406
534
  assert.doesNotThrow(() => {
@@ -416,23 +544,36 @@ describe('plugin-logger', () => {
416
544
  const [filtered] = webex.logger.filter(msg);
417
545
 
418
546
  assert.nestedProperty(msg, 'headers.authorization', 'it does not alter the original message');
419
- assert.nestedProperty(msg, 'options.headers.authorization', 'it does not alter the original message');
420
-
421
- assert.notNestedProperty(filtered, 'headers.authorization', 'it removes headers.authorization');
422
- assert.notNestedProperty(filtered, 'options.headers.authorization', 'it removes options.headers.authorization');
423
- assert.nestedProperty(msg, 'options.headers.trackingid', 'it does not remove other header values');
424
- assert.nestedProperty(filtered, 'options.headers.trackingid', 'it does not remove other header values');
547
+ assert.nestedProperty(
548
+ msg,
549
+ 'options.headers.authorization',
550
+ 'it does not alter the original message'
551
+ );
552
+
553
+ assert.notNestedProperty(
554
+ filtered,
555
+ 'headers.authorization',
556
+ 'it removes headers.authorization'
557
+ );
558
+ assert.notNestedProperty(
559
+ filtered,
560
+ 'options.headers.authorization',
561
+ 'it removes options.headers.authorization'
562
+ );
563
+ assert.nestedProperty(
564
+ msg,
565
+ 'options.headers.trackingid',
566
+ 'it does not remove other header values'
567
+ );
568
+ assert.nestedProperty(
569
+ filtered,
570
+ 'options.headers.trackingid',
571
+ 'it does not remove other header values'
572
+ );
425
573
  });
426
574
  });
427
575
 
428
- [
429
- 'error',
430
- 'warn',
431
- 'log',
432
- 'info',
433
- 'debug',
434
- 'trace'
435
- ].forEach((level) => {
576
+ ['error', 'warn', 'log', 'info', 'debug', 'trace'].forEach((level) => {
436
577
  describe(`#${level}()`, () => {
437
578
  it(`proxies console.${level}`, () => {
438
579
  webex.logger.config.level = level;
@@ -446,13 +587,13 @@ describe('plugin-logger', () => {
446
587
  webex.logger[level]({
447
588
  headers: {
448
589
  authorization: 'Bearer',
449
- trackingid: '123'
450
- }
590
+ trackingid: '123',
591
+ },
451
592
  });
452
593
  assert.calledWith(console[impl(level)], 'wx-js-sdk', {
453
594
  headers: {
454
- trackingid: '123'
455
- }
595
+ trackingid: '123',
596
+ },
456
597
  });
457
598
  });
458
599
  });
@@ -463,7 +604,7 @@ describe('plugin-logger', () => {
463
604
  webex.config.logger.level = 'trace';
464
605
  webex.logger.log({
465
606
  Authorization: 'XXXXXXX',
466
- Key: 'myKey'
607
+ Key: 'myKey',
467
608
  });
468
609
 
469
610
  // Assert auth was filtered
@@ -471,7 +612,7 @@ describe('plugin-logger', () => {
471
612
 
472
613
  webex.logger.log({
473
614
  authorization: 'XXXXXXX',
474
- Key: 'myKey'
615
+ Key: 'myKey',
475
616
  });
476
617
 
477
618
  assert.calledWith(console.log, 'wx-js-sdk', {Key: 'myKey'});
@@ -493,7 +634,7 @@ describe('plugin-logger', () => {
493
634
  const object = {
494
635
  authorization: 'XXXXXXX',
495
636
  string: 'test@cisco.com',
496
- Key: 'myKey'
637
+ Key: 'myKey',
497
638
  };
498
639
 
499
640
  // Add a circular reference to the object
@@ -503,7 +644,7 @@ describe('plugin-logger', () => {
503
644
 
504
645
  const expected = {
505
646
  string: '[REDACTED]',
506
- Key: 'myKey'
647
+ Key: 'myKey',
507
648
  };
508
649
 
509
650
  expected.selfReference = expected;
@@ -530,8 +671,8 @@ describe('plugin-logger', () => {
530
671
  otherPrimativeNum: 6,
531
672
  subPrimativeBool: true,
532
673
  otherPrimativeBool: false,
533
- subPrimativeSymbol: sym
534
- }
674
+ subPrimativeSymbol: sym,
675
+ },
535
676
  };
536
677
 
537
678
  object.subObject.circularObjectRef = object;
@@ -555,8 +696,8 @@ describe('plugin-logger', () => {
555
696
  otherPrimativeBool: false,
556
697
  subPrimativeSymbol: sym,
557
698
  circularObjectRef: object,
558
- circularFunctionRef: func
559
- }
699
+ circularFunctionRef: func,
700
+ },
560
701
  });
561
702
  });
562
703
  });
@@ -585,7 +726,6 @@ describe('plugin-logger', () => {
585
726
  }
586
727
  }
587
728
 
588
-
589
729
  it('formats mixed log types in order by default', async () => {
590
730
  for (let i = 0; i < 10; i += 1) {
591
731
  sendRandomLog(i);
@@ -663,4 +803,42 @@ describe('plugin-logger', () => {
663
803
  });
664
804
  });
665
805
  });
806
+ describe('limit', () => {
807
+ function logMessages() {
808
+ return webex.logger.buffer.map((item) => item[3]);
809
+ }
810
+
811
+ it('can be increased in runtime', () => {
812
+ webex.logger.config.historyLength = 5;
813
+ for (let i = 0; i < 10; i += 1) {
814
+ webex.logger.log(i);
815
+ }
816
+
817
+ assert.deepEqual(logMessages(), [5, 6, 7, 8, 9]);
818
+ assert.lengthOf(webex.logger.buffer, 5);
819
+
820
+ webex.logger.config.historyLength = 10;
821
+ webex.logger.log(10);
822
+ assert.deepEqual(logMessages(), [5, 6, 7, 8, 9, 10]);
823
+ assert.lengthOf(webex.logger.buffer, 6);
824
+ });
825
+
826
+ it('can be decreased in runtime', () => {
827
+ for (let i = 0; i < 10; i += 1) {
828
+ webex.logger.log(i);
829
+ }
830
+
831
+ assert.deepEqual(logMessages(), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
832
+ assert.lengthOf(webex.logger.buffer, 10);
833
+
834
+ webex.logger.config.historyLength = 5;
835
+
836
+ // Log buffer truncated when the next log added
837
+ assert.lengthOf(webex.logger.buffer, 10);
838
+
839
+ webex.logger.log(10);
840
+ assert.deepEqual(logMessages(), [6, 7, 8, 9, 10]);
841
+ assert.lengthOf(webex.logger.buffer, 5);
842
+ });
843
+ });
666
844
  });