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