@webex/plugin-logger 3.0.0-beta.4 → 3.0.0-beta.400
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 +1 -5
- package/dist/config.js.map +1 -1
- package/dist/index.js +1 -13
- package/dist/index.js.map +1 -1
- package/dist/logger.js +53 -78
- package/dist/logger.js.map +1 -1
- package/package.json +7 -7
- package/src/config.js +2 -2
- package/src/index.js +2 -5
- package/src/logger.js +80 -44
- package/test/unit/spec/logger.js +340 -96
package/test/unit/spec/logger.js
CHANGED
|
@@ -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,18 +173,64 @@ 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);
|
|
184
185
|
assert.lengthOf(webex.logger.buffer, 1);
|
|
185
186
|
assert.match(webex.logger.buffer[0][3], /WebexHttpError/g);
|
|
186
187
|
});
|
|
188
|
+
|
|
189
|
+
it('formats objects as strings passed to the logger for readability not [Object object]', async () => {
|
|
190
|
+
webex.config.logger.level = 'trace';
|
|
191
|
+
const obj = {
|
|
192
|
+
headers: {
|
|
193
|
+
authorization: 'Bearer',
|
|
194
|
+
trackingid: '123',
|
|
195
|
+
},
|
|
196
|
+
test: 'object',
|
|
197
|
+
nested: {
|
|
198
|
+
test2: 'object2',
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
webex.logger.log('foo', 'bar', obj);
|
|
203
|
+
assert.lengthOf(webex.logger.buffer, 1);
|
|
204
|
+
assert.lengthOf(webex.logger.buffer[0], 6);
|
|
205
|
+
assert.deepEqual(webex.logger.buffer[0][2], 'wx-js-sdk');
|
|
206
|
+
assert.deepEqual(webex.logger.buffer[0][3], 'foo');
|
|
207
|
+
assert.deepEqual(webex.logger.buffer[0][4], 'bar');
|
|
208
|
+
assert.deepEqual(webex.logger.buffer[0][5], '{"headers":{"trackingid":"123"},"test":"object","nested":{"test2":"object2"}}');
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('formats objects as strings passed to the logger for readability not [Object object] w/ circular reference', async () => {
|
|
212
|
+
webex.config.logger.level = 'trace';
|
|
213
|
+
const obj = {
|
|
214
|
+
headers: {
|
|
215
|
+
authorization: 'Bearer',
|
|
216
|
+
trackingid: '123',
|
|
217
|
+
},
|
|
218
|
+
test: 'object',
|
|
219
|
+
nested: {
|
|
220
|
+
test2: 'object2',
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
obj.selfReference = obj;
|
|
225
|
+
|
|
226
|
+
webex.logger.log('foo', 'bar', obj);
|
|
227
|
+
assert.lengthOf(webex.logger.buffer, 1);
|
|
228
|
+
assert.lengthOf(webex.logger.buffer[0], 6);
|
|
229
|
+
assert.deepEqual(webex.logger.buffer[0][2], 'wx-js-sdk');
|
|
230
|
+
assert.deepEqual(webex.logger.buffer[0][3], 'foo');
|
|
231
|
+
assert.deepEqual(webex.logger.buffer[0][4], 'bar');
|
|
232
|
+
assert.deepEqual(webex.logger.buffer[0][5], '{"headers":{"trackingid":"123"},"test":"object","nested":{"test2":"object2"}}');
|
|
233
|
+
});
|
|
187
234
|
});
|
|
188
235
|
|
|
189
236
|
// We can't manipulate NODE_ENV in karma, tests, so run this chunk only in
|
|
@@ -196,60 +243,186 @@ describe('plugin-logger', () => {
|
|
|
196
243
|
function testLevels(logType, logConfigSetting) {
|
|
197
244
|
/* eslint max-statements: [0] */
|
|
198
245
|
webex.logger.config[logConfigSetting] = 'trace';
|
|
199
|
-
assert.isTrue(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
assert.isTrue(
|
|
204
|
-
|
|
246
|
+
assert.isTrue(
|
|
247
|
+
webex.logger.shouldPrint('error', logType),
|
|
248
|
+
'it prints `error` logs when the level is `trace`'
|
|
249
|
+
);
|
|
250
|
+
assert.isTrue(
|
|
251
|
+
webex.logger.shouldPrint('warn', logType),
|
|
252
|
+
'it prints `warn` logs when the level is `trace`'
|
|
253
|
+
);
|
|
254
|
+
assert.isTrue(
|
|
255
|
+
webex.logger.shouldPrint('log', logType),
|
|
256
|
+
'it prints `log` logs when the level is `trace`'
|
|
257
|
+
);
|
|
258
|
+
assert.isTrue(
|
|
259
|
+
webex.logger.shouldPrint('info', logType),
|
|
260
|
+
'it prints `info` logs when the level is `trace`'
|
|
261
|
+
);
|
|
262
|
+
assert.isTrue(
|
|
263
|
+
webex.logger.shouldPrint('debug', logType),
|
|
264
|
+
'it prints `debug` logs when the level is `trace`'
|
|
265
|
+
);
|
|
266
|
+
assert.isTrue(
|
|
267
|
+
webex.logger.shouldPrint('trace', logType),
|
|
268
|
+
'it prints `trace` logs when the level is `trace`'
|
|
269
|
+
);
|
|
205
270
|
|
|
206
271
|
webex.logger.config[logConfigSetting] = 'debug';
|
|
207
|
-
assert.isTrue(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
assert.isTrue(
|
|
212
|
-
|
|
272
|
+
assert.isTrue(
|
|
273
|
+
webex.logger.shouldPrint('error', logType),
|
|
274
|
+
'it prints `error` logs when the level is `debug`'
|
|
275
|
+
);
|
|
276
|
+
assert.isTrue(
|
|
277
|
+
webex.logger.shouldPrint('warn', logType),
|
|
278
|
+
'it prints `warn` logs when the level is `debug`'
|
|
279
|
+
);
|
|
280
|
+
assert.isTrue(
|
|
281
|
+
webex.logger.shouldPrint('log', logType),
|
|
282
|
+
'it prints `log` logs when the level is `debug`'
|
|
283
|
+
);
|
|
284
|
+
assert.isTrue(
|
|
285
|
+
webex.logger.shouldPrint('info', logType),
|
|
286
|
+
'it prints `info` logs when the level is `debug`'
|
|
287
|
+
);
|
|
288
|
+
assert.isTrue(
|
|
289
|
+
webex.logger.shouldPrint('debug', logType),
|
|
290
|
+
'it prints `debug` logs when the level is `debug`'
|
|
291
|
+
);
|
|
292
|
+
assert.isFalse(
|
|
293
|
+
webex.logger.shouldPrint('trace', logType),
|
|
294
|
+
'it does not print `trace` logs when the level is `debug`'
|
|
295
|
+
);
|
|
213
296
|
|
|
214
297
|
webex.logger.config[logConfigSetting] = 'info';
|
|
215
|
-
assert.isTrue(
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
assert.
|
|
220
|
-
|
|
298
|
+
assert.isTrue(
|
|
299
|
+
webex.logger.shouldPrint('error', logType),
|
|
300
|
+
'it prints `error` logs when the level is `info`'
|
|
301
|
+
);
|
|
302
|
+
assert.isTrue(
|
|
303
|
+
webex.logger.shouldPrint('warn', logType),
|
|
304
|
+
'it prints `warn` logs when the level is `info`'
|
|
305
|
+
);
|
|
306
|
+
assert.isTrue(
|
|
307
|
+
webex.logger.shouldPrint('log', logType),
|
|
308
|
+
'it prints `log` logs when the level is `info`'
|
|
309
|
+
);
|
|
310
|
+
assert.isTrue(
|
|
311
|
+
webex.logger.shouldPrint('info', logType),
|
|
312
|
+
'it prints `info` logs when the level is `info`'
|
|
313
|
+
);
|
|
314
|
+
assert.isFalse(
|
|
315
|
+
webex.logger.shouldPrint('debug', logType),
|
|
316
|
+
'it does not print `debug` logs when the level is `info`'
|
|
317
|
+
);
|
|
318
|
+
assert.isFalse(
|
|
319
|
+
webex.logger.shouldPrint('trace', logType),
|
|
320
|
+
'it does not print `trace` logs when the level is `info`'
|
|
321
|
+
);
|
|
221
322
|
|
|
222
323
|
webex.logger.config[logConfigSetting] = 'log';
|
|
223
|
-
assert.isTrue(
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
assert.
|
|
228
|
-
|
|
324
|
+
assert.isTrue(
|
|
325
|
+
webex.logger.shouldPrint('error', logType),
|
|
326
|
+
'it prints `error` logs when the level is `log`'
|
|
327
|
+
);
|
|
328
|
+
assert.isTrue(
|
|
329
|
+
webex.logger.shouldPrint('warn', logType),
|
|
330
|
+
'it prints `warn` logs when the level is `log`'
|
|
331
|
+
);
|
|
332
|
+
assert.isTrue(
|
|
333
|
+
webex.logger.shouldPrint('log', logType),
|
|
334
|
+
'it prints `log` logs when the level is `log`'
|
|
335
|
+
);
|
|
336
|
+
assert.isFalse(
|
|
337
|
+
webex.logger.shouldPrint('info', logType),
|
|
338
|
+
'it does not print `info` logs when the level is `log`'
|
|
339
|
+
);
|
|
340
|
+
assert.isFalse(
|
|
341
|
+
webex.logger.shouldPrint('debug', logType),
|
|
342
|
+
'it does not print `debug` logs when the level is `log`'
|
|
343
|
+
);
|
|
344
|
+
assert.isFalse(
|
|
345
|
+
webex.logger.shouldPrint('trace', logType),
|
|
346
|
+
'it does not print `trace` logs when the level is `log`'
|
|
347
|
+
);
|
|
229
348
|
|
|
230
349
|
webex.logger.config[logConfigSetting] = 'warn';
|
|
231
|
-
assert.isTrue(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
assert.
|
|
236
|
-
|
|
350
|
+
assert.isTrue(
|
|
351
|
+
webex.logger.shouldPrint('error', logType),
|
|
352
|
+
'it prints `error` logs when the level is `warn`'
|
|
353
|
+
);
|
|
354
|
+
assert.isTrue(
|
|
355
|
+
webex.logger.shouldPrint('warn', logType),
|
|
356
|
+
'it prints `warn` logs when the level is `warn`'
|
|
357
|
+
);
|
|
358
|
+
assert.isFalse(
|
|
359
|
+
webex.logger.shouldPrint('log', logType),
|
|
360
|
+
'it does not print `log` logs when the level is `warn`'
|
|
361
|
+
);
|
|
362
|
+
assert.isFalse(
|
|
363
|
+
webex.logger.shouldPrint('info', logType),
|
|
364
|
+
'it does not print `info` logs when the level is `warn`'
|
|
365
|
+
);
|
|
366
|
+
assert.isFalse(
|
|
367
|
+
webex.logger.shouldPrint('debug', logType),
|
|
368
|
+
'it does not print `debug` logs when the level is `warn`'
|
|
369
|
+
);
|
|
370
|
+
assert.isFalse(
|
|
371
|
+
webex.logger.shouldPrint('trace', logType),
|
|
372
|
+
'it does not print `trace` logs when the level is `warn`'
|
|
373
|
+
);
|
|
237
374
|
|
|
238
375
|
webex.logger.config[logConfigSetting] = 'error';
|
|
239
|
-
assert.isTrue(
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
assert.isFalse(
|
|
244
|
-
|
|
376
|
+
assert.isTrue(
|
|
377
|
+
webex.logger.shouldPrint('error', logType),
|
|
378
|
+
'it prints `error` logs when the level is `error`'
|
|
379
|
+
);
|
|
380
|
+
assert.isFalse(
|
|
381
|
+
webex.logger.shouldPrint('warn', logType),
|
|
382
|
+
'it does not print `warn` logs when the level `error` is '
|
|
383
|
+
);
|
|
384
|
+
assert.isFalse(
|
|
385
|
+
webex.logger.shouldPrint('log', logType),
|
|
386
|
+
'it does not print `log` logs when the level is `error`'
|
|
387
|
+
);
|
|
388
|
+
assert.isFalse(
|
|
389
|
+
webex.logger.shouldPrint('info', logType),
|
|
390
|
+
'it does not print `info` logs when the level is `error`'
|
|
391
|
+
);
|
|
392
|
+
assert.isFalse(
|
|
393
|
+
webex.logger.shouldPrint('debug', logType),
|
|
394
|
+
'it does not print `debug` logs when the level is `error`'
|
|
395
|
+
);
|
|
396
|
+
assert.isFalse(
|
|
397
|
+
webex.logger.shouldPrint('trace', logType),
|
|
398
|
+
'it does not print `trace` logs when the level is `error`'
|
|
399
|
+
);
|
|
245
400
|
|
|
246
401
|
webex.logger.config[logConfigSetting] = 'silent';
|
|
247
|
-
assert.isFalse(
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
assert.isFalse(
|
|
252
|
-
|
|
402
|
+
assert.isFalse(
|
|
403
|
+
webex.logger.shouldPrint('error', logType),
|
|
404
|
+
'it does not print `error` logs when the level is `silent`'
|
|
405
|
+
);
|
|
406
|
+
assert.isFalse(
|
|
407
|
+
webex.logger.shouldPrint('warn', logType),
|
|
408
|
+
'it does not print `warn` logs when the level is `silent`'
|
|
409
|
+
);
|
|
410
|
+
assert.isFalse(
|
|
411
|
+
webex.logger.shouldPrint('log', logType),
|
|
412
|
+
'it does not print `log` logs when the level is `silent`'
|
|
413
|
+
);
|
|
414
|
+
assert.isFalse(
|
|
415
|
+
webex.logger.shouldPrint('info', logType),
|
|
416
|
+
'it does not print `info` logs when the level is `silent`'
|
|
417
|
+
);
|
|
418
|
+
assert.isFalse(
|
|
419
|
+
webex.logger.shouldPrint('debug', logType),
|
|
420
|
+
'it does not print `debug` logs when the level is `silent`'
|
|
421
|
+
);
|
|
422
|
+
assert.isFalse(
|
|
423
|
+
webex.logger.shouldPrint('trace', logType),
|
|
424
|
+
'it does not print `trace` logs when the level is `silent`'
|
|
425
|
+
);
|
|
253
426
|
}
|
|
254
427
|
|
|
255
428
|
it('indicates whether or not the desired log should be printed at the current log level', () => {
|
|
@@ -310,20 +483,20 @@ describe('plugin-logger', () => {
|
|
|
310
483
|
developer: {
|
|
311
484
|
get() {
|
|
312
485
|
return 'info';
|
|
313
|
-
}
|
|
486
|
+
},
|
|
314
487
|
},
|
|
315
488
|
entitlement: {
|
|
316
489
|
get() {
|
|
317
490
|
return false;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
491
|
+
},
|
|
492
|
+
},
|
|
493
|
+
},
|
|
321
494
|
};
|
|
322
495
|
webex.logger.info('test');
|
|
323
496
|
assert.called(console.info);
|
|
324
497
|
});
|
|
325
498
|
|
|
326
|
-
nodeOnly(it)(
|
|
499
|
+
nodeOnly(it)("doesn't break if the feature toggle is set to an incorrect value", () => {
|
|
327
500
|
assert.doesNotThrow(() => {
|
|
328
501
|
assert.notCalled(console.info);
|
|
329
502
|
webex.logger.info('test');
|
|
@@ -334,14 +507,14 @@ describe('plugin-logger', () => {
|
|
|
334
507
|
developer: {
|
|
335
508
|
get() {
|
|
336
509
|
return 'not-a-log-method';
|
|
337
|
-
}
|
|
510
|
+
},
|
|
338
511
|
},
|
|
339
512
|
entitlement: {
|
|
340
513
|
get() {
|
|
341
514
|
return false;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
515
|
+
},
|
|
516
|
+
},
|
|
517
|
+
},
|
|
345
518
|
};
|
|
346
519
|
webex.logger.info('test');
|
|
347
520
|
assert.notCalled(console.info);
|
|
@@ -378,29 +551,30 @@ describe('plugin-logger', () => {
|
|
|
378
551
|
});
|
|
379
552
|
});
|
|
380
553
|
|
|
381
|
-
|
|
382
554
|
describe('#filter', () => {
|
|
383
555
|
it('redacts email addresses', () => {
|
|
384
556
|
const message = {
|
|
385
|
-
blarg: 'test@example.com'
|
|
557
|
+
blarg: 'test@example.com',
|
|
386
558
|
};
|
|
387
559
|
|
|
388
|
-
assert.deepEqual(webex.logger.filter(message), [
|
|
389
|
-
|
|
390
|
-
|
|
560
|
+
assert.deepEqual(webex.logger.filter(message), [
|
|
561
|
+
{
|
|
562
|
+
blarg: '[REDACTED]',
|
|
563
|
+
},
|
|
564
|
+
]);
|
|
391
565
|
});
|
|
392
566
|
|
|
393
567
|
it('strips auth headers from log output', () => {
|
|
394
568
|
const msg = {
|
|
395
569
|
headers: {
|
|
396
|
-
authorization: 'Bearer'
|
|
570
|
+
authorization: 'Bearer',
|
|
397
571
|
},
|
|
398
572
|
options: {
|
|
399
573
|
headers: {
|
|
400
574
|
trackingid: '123',
|
|
401
|
-
authorization: 'Bearer'
|
|
402
|
-
}
|
|
403
|
-
}
|
|
575
|
+
authorization: 'Bearer',
|
|
576
|
+
},
|
|
577
|
+
},
|
|
404
578
|
};
|
|
405
579
|
|
|
406
580
|
assert.doesNotThrow(() => {
|
|
@@ -416,23 +590,36 @@ describe('plugin-logger', () => {
|
|
|
416
590
|
const [filtered] = webex.logger.filter(msg);
|
|
417
591
|
|
|
418
592
|
assert.nestedProperty(msg, 'headers.authorization', 'it does not alter the original message');
|
|
419
|
-
assert.nestedProperty(
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
593
|
+
assert.nestedProperty(
|
|
594
|
+
msg,
|
|
595
|
+
'options.headers.authorization',
|
|
596
|
+
'it does not alter the original message'
|
|
597
|
+
);
|
|
598
|
+
|
|
599
|
+
assert.notNestedProperty(
|
|
600
|
+
filtered,
|
|
601
|
+
'headers.authorization',
|
|
602
|
+
'it removes headers.authorization'
|
|
603
|
+
);
|
|
604
|
+
assert.notNestedProperty(
|
|
605
|
+
filtered,
|
|
606
|
+
'options.headers.authorization',
|
|
607
|
+
'it removes options.headers.authorization'
|
|
608
|
+
);
|
|
609
|
+
assert.nestedProperty(
|
|
610
|
+
msg,
|
|
611
|
+
'options.headers.trackingid',
|
|
612
|
+
'it does not remove other header values'
|
|
613
|
+
);
|
|
614
|
+
assert.nestedProperty(
|
|
615
|
+
filtered,
|
|
616
|
+
'options.headers.trackingid',
|
|
617
|
+
'it does not remove other header values'
|
|
618
|
+
);
|
|
425
619
|
});
|
|
426
620
|
});
|
|
427
621
|
|
|
428
|
-
[
|
|
429
|
-
'error',
|
|
430
|
-
'warn',
|
|
431
|
-
'log',
|
|
432
|
-
'info',
|
|
433
|
-
'debug',
|
|
434
|
-
'trace'
|
|
435
|
-
].forEach((level) => {
|
|
622
|
+
['error', 'warn', 'log', 'info', 'debug', 'trace'].forEach((level) => {
|
|
436
623
|
describe(`#${level}()`, () => {
|
|
437
624
|
it(`proxies console.${level}`, () => {
|
|
438
625
|
webex.logger.config.level = level;
|
|
@@ -446,13 +633,13 @@ describe('plugin-logger', () => {
|
|
|
446
633
|
webex.logger[level]({
|
|
447
634
|
headers: {
|
|
448
635
|
authorization: 'Bearer',
|
|
449
|
-
trackingid: '123'
|
|
450
|
-
}
|
|
636
|
+
trackingid: '123',
|
|
637
|
+
},
|
|
451
638
|
});
|
|
452
639
|
assert.calledWith(console[impl(level)], 'wx-js-sdk', {
|
|
453
640
|
headers: {
|
|
454
|
-
trackingid: '123'
|
|
455
|
-
}
|
|
641
|
+
trackingid: '123',
|
|
642
|
+
},
|
|
456
643
|
});
|
|
457
644
|
});
|
|
458
645
|
});
|
|
@@ -463,7 +650,7 @@ describe('plugin-logger', () => {
|
|
|
463
650
|
webex.config.logger.level = 'trace';
|
|
464
651
|
webex.logger.log({
|
|
465
652
|
Authorization: 'XXXXXXX',
|
|
466
|
-
Key: 'myKey'
|
|
653
|
+
Key: 'myKey',
|
|
467
654
|
});
|
|
468
655
|
|
|
469
656
|
// Assert auth was filtered
|
|
@@ -471,7 +658,7 @@ describe('plugin-logger', () => {
|
|
|
471
658
|
|
|
472
659
|
webex.logger.log({
|
|
473
660
|
authorization: 'XXXXXXX',
|
|
474
|
-
Key: 'myKey'
|
|
661
|
+
Key: 'myKey',
|
|
475
662
|
});
|
|
476
663
|
|
|
477
664
|
assert.calledWith(console.log, 'wx-js-sdk', {Key: 'myKey'});
|
|
@@ -487,13 +674,33 @@ describe('plugin-logger', () => {
|
|
|
487
674
|
assert.calledWith(console.log, 'wx-js-sdk', '[REDACTED]');
|
|
488
675
|
});
|
|
489
676
|
|
|
677
|
+
it('redact MTID', () => {
|
|
678
|
+
webex.config.logger.level = 'trace';
|
|
679
|
+
|
|
680
|
+
const destination = 'https://example.com/example/j.php?MTID=m678957bc1eff989c2176b43ead9d46b5';
|
|
681
|
+
|
|
682
|
+
webex.logger.log(
|
|
683
|
+
`Info Unable to fetch meeting info for ${destination}.`
|
|
684
|
+
);
|
|
685
|
+
assert.calledWith(console.log, 'wx-js-sdk', 'Info Unable to fetch meeting info for https://example.com/example/j.php?MTID=[REDACTED]');
|
|
686
|
+
|
|
687
|
+
webex.logger.log('https://example.com/example/j.php?MTID=m678957bc1eff989c2176b43ead9d46b5&abcdefg');
|
|
688
|
+
assert.calledWith(console.log, 'wx-js-sdk', 'https://example.com/example/j.php?MTID=[REDACTED]&abcdefg');
|
|
689
|
+
|
|
690
|
+
webex.logger.log('https://example.com/example/j.php?MTID=m678957bc1eff989c2176b43ead9d46b5$abcdefg');
|
|
691
|
+
assert.calledWith(console.log, 'wx-js-sdk', 'https://example.com/example/j.php?MTID=[REDACTED]$abcdefg');
|
|
692
|
+
|
|
693
|
+
webex.logger.log('https://example.com/example/j.php?MTID=m678957bc1eff989c2176b43ead9d46b5#abcdefg');
|
|
694
|
+
assert.calledWith(console.log, 'wx-js-sdk', 'https://example.com/example/j.php?MTID=[REDACTED]#abcdefg');
|
|
695
|
+
});
|
|
696
|
+
|
|
490
697
|
it('handle circular references', () => {
|
|
491
698
|
webex.config.logger.level = 'trace';
|
|
492
699
|
|
|
493
700
|
const object = {
|
|
494
701
|
authorization: 'XXXXXXX',
|
|
495
702
|
string: 'test@cisco.com',
|
|
496
|
-
Key: 'myKey'
|
|
703
|
+
Key: 'myKey',
|
|
497
704
|
};
|
|
498
705
|
|
|
499
706
|
// Add a circular reference to the object
|
|
@@ -503,7 +710,7 @@ describe('plugin-logger', () => {
|
|
|
503
710
|
|
|
504
711
|
const expected = {
|
|
505
712
|
string: '[REDACTED]',
|
|
506
|
-
Key: 'myKey'
|
|
713
|
+
Key: 'myKey',
|
|
507
714
|
};
|
|
508
715
|
|
|
509
716
|
expected.selfReference = expected;
|
|
@@ -530,8 +737,8 @@ describe('plugin-logger', () => {
|
|
|
530
737
|
otherPrimativeNum: 6,
|
|
531
738
|
subPrimativeBool: true,
|
|
532
739
|
otherPrimativeBool: false,
|
|
533
|
-
subPrimativeSymbol: sym
|
|
534
|
-
}
|
|
740
|
+
subPrimativeSymbol: sym,
|
|
741
|
+
},
|
|
535
742
|
};
|
|
536
743
|
|
|
537
744
|
object.subObject.circularObjectRef = object;
|
|
@@ -555,8 +762,8 @@ describe('plugin-logger', () => {
|
|
|
555
762
|
otherPrimativeBool: false,
|
|
556
763
|
subPrimativeSymbol: sym,
|
|
557
764
|
circularObjectRef: object,
|
|
558
|
-
circularFunctionRef: func
|
|
559
|
-
}
|
|
765
|
+
circularFunctionRef: func,
|
|
766
|
+
},
|
|
560
767
|
});
|
|
561
768
|
});
|
|
562
769
|
});
|
|
@@ -585,7 +792,6 @@ describe('plugin-logger', () => {
|
|
|
585
792
|
}
|
|
586
793
|
}
|
|
587
794
|
|
|
588
|
-
|
|
589
795
|
it('formats mixed log types in order by default', async () => {
|
|
590
796
|
for (let i = 0; i < 10; i += 1) {
|
|
591
797
|
sendRandomLog(i);
|
|
@@ -663,4 +869,42 @@ describe('plugin-logger', () => {
|
|
|
663
869
|
});
|
|
664
870
|
});
|
|
665
871
|
});
|
|
872
|
+
describe('limit', () => {
|
|
873
|
+
function logMessages() {
|
|
874
|
+
return webex.logger.buffer.map((item) => item[3]);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
it('can be increased in runtime', () => {
|
|
878
|
+
webex.logger.config.historyLength = 5;
|
|
879
|
+
for (let i = 0; i < 10; i += 1) {
|
|
880
|
+
webex.logger.log(i);
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
assert.deepEqual(logMessages(), [5, 6, 7, 8, 9]);
|
|
884
|
+
assert.lengthOf(webex.logger.buffer, 5);
|
|
885
|
+
|
|
886
|
+
webex.logger.config.historyLength = 10;
|
|
887
|
+
webex.logger.log(10);
|
|
888
|
+
assert.deepEqual(logMessages(), [5, 6, 7, 8, 9, 10]);
|
|
889
|
+
assert.lengthOf(webex.logger.buffer, 6);
|
|
890
|
+
});
|
|
891
|
+
|
|
892
|
+
it('can be decreased in runtime', () => {
|
|
893
|
+
for (let i = 0; i < 10; i += 1) {
|
|
894
|
+
webex.logger.log(i);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
assert.deepEqual(logMessages(), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
898
|
+
assert.lengthOf(webex.logger.buffer, 10);
|
|
899
|
+
|
|
900
|
+
webex.logger.config.historyLength = 5;
|
|
901
|
+
|
|
902
|
+
// Log buffer truncated when the next log added
|
|
903
|
+
assert.lengthOf(webex.logger.buffer, 10);
|
|
904
|
+
|
|
905
|
+
webex.logger.log(10);
|
|
906
|
+
assert.deepEqual(logMessages(), [6, 7, 8, 9, 10]);
|
|
907
|
+
assert.lengthOf(webex.logger.buffer, 5);
|
|
908
|
+
});
|
|
909
|
+
});
|
|
666
910
|
});
|