@webex/plugin-logger 3.12.0-task-refactor.1 → 3.12.0-webex-services-ready.1
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/logger.js +37 -4
- package/dist/logger.js.map +1 -1
- package/package.json +10 -10
- package/src/logger.js +36 -0
- package/test/unit/spec/logger.js +318 -54
package/dist/logger.js
CHANGED
|
@@ -117,7 +117,8 @@ var Logger = _webexCore.WebexPlugin.extend({
|
|
|
117
117
|
default: function _default() {
|
|
118
118
|
return {
|
|
119
119
|
buffer: [],
|
|
120
|
-
nextIndex: 0
|
|
120
|
+
nextIndex: 0,
|
|
121
|
+
lastSubmitted: 0
|
|
121
122
|
};
|
|
122
123
|
}
|
|
123
124
|
},
|
|
@@ -133,7 +134,8 @@ var Logger = _webexCore.WebexPlugin.extend({
|
|
|
133
134
|
default: function _default() {
|
|
134
135
|
return {
|
|
135
136
|
buffer: [],
|
|
136
|
-
nextIndex: 0
|
|
137
|
+
nextIndex: 0,
|
|
138
|
+
lastSubmitted: 0
|
|
137
139
|
};
|
|
138
140
|
}
|
|
139
141
|
},
|
|
@@ -142,7 +144,8 @@ var Logger = _webexCore.WebexPlugin.extend({
|
|
|
142
144
|
default: function _default() {
|
|
143
145
|
return {
|
|
144
146
|
buffer: [],
|
|
145
|
-
nextIndex: 0
|
|
147
|
+
nextIndex: 0,
|
|
148
|
+
lastSubmitted: 0
|
|
146
149
|
};
|
|
147
150
|
}
|
|
148
151
|
}
|
|
@@ -309,7 +312,33 @@ var Logger = _webexCore.WebexPlugin.extend({
|
|
|
309
312
|
}
|
|
310
313
|
return buffer.join('\n');
|
|
311
314
|
},
|
|
312
|
-
|
|
315
|
+
/**
|
|
316
|
+
* Update the last submitted index in the buffers to the current nextIndex
|
|
317
|
+
*
|
|
318
|
+
* @returns {void}
|
|
319
|
+
*/
|
|
320
|
+
updateLastSubmittedIndex: function updateLastSubmittedIndex() {
|
|
321
|
+
if (this.config.separateLogBuffers) {
|
|
322
|
+
this.clientBuffer.lastSubmitted = this.clientBuffer.nextIndex;
|
|
323
|
+
this.sdkBuffer.lastSubmitted = this.sdkBuffer.nextIndex;
|
|
324
|
+
} else {
|
|
325
|
+
this.buffer.lastSubmitted = this.buffer.nextIndex;
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
/**
|
|
329
|
+
* Reset the nextIndex in the buffers to the last successful upload index, effectively including any logs since the last successful upload in the next upload
|
|
330
|
+
*
|
|
331
|
+
* @returns {void}
|
|
332
|
+
*/
|
|
333
|
+
resetBufferToLastSuccessfulUpload: function resetBufferToLastSuccessfulUpload() {
|
|
334
|
+
if (this.config.separateLogBuffers) {
|
|
335
|
+
this.clientBuffer.nextIndex = this.clientBuffer.lastSubmitted;
|
|
336
|
+
this.sdkBuffer.nextIndex = this.sdkBuffer.lastSubmitted;
|
|
337
|
+
} else {
|
|
338
|
+
this.buffer.nextIndex = this.buffer.lastSubmitted;
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
version: "3.12.0-webex-services-ready.1"
|
|
313
342
|
});
|
|
314
343
|
|
|
315
344
|
/**
|
|
@@ -411,6 +440,10 @@ function makeLoggerMethod(level, impl, type) {
|
|
|
411
440
|
if (bufferRef.nextIndex < 0) {
|
|
412
441
|
bufferRef.nextIndex = 0;
|
|
413
442
|
}
|
|
443
|
+
bufferRef.lastSubmitted -= deleteCount;
|
|
444
|
+
if (bufferRef.lastSubmitted < 0) {
|
|
445
|
+
bufferRef.lastSubmitted = 0;
|
|
446
|
+
}
|
|
414
447
|
}
|
|
415
448
|
if (level === 'group') this.groupLevel += 1;
|
|
416
449
|
if (level === 'groupEnd' && this.groupLevel > 0) this.groupLevel -= 1;
|
package/dist/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_common","require","_webexCore","_lodash","precedence","silent","group","groupEnd","error","warn","log","info","debug","trace","levels","exports","_keys","default","filter","level","fallbacks","LOG_TYPES","SDK","CLIENT","SDK_LOG_TYPE_NAME","authTokenKeyPattern","walkAndFilter","object","visited","arguments","length","undefined","includes","push","isArray","map","o","isObject","isString","patterns","containsEmails","test","replace","containsMTID","_i","_Object$entries","_entries","_Object$entries$_i","_slicedToArray2","key","value","_deleteProperty","Logger","WebexPlugin","extend","namespace","derived","cache","fn","getCurrentLevel","client_level","getCurrentClientLevel","session","buffer","type","nextIndex","groupLevel","sdkBuffer","clientBuffer","_len","args","Array","_key2","arg","Error","process","env","NODE_ENV","inBrowser","ret","toString","stack","cloneDeep","shouldPrint","shouldBuffer","config","bufferLogLevel","WEBEX_LOG_LEVEL","webex","internal","device","features","developer","get","clientLevel","formatLogs","options","getDate","_options$diff","diff","clientIndex","sdkIndex","separateLogBuffers","Date","slice","join","version","makeLoggerMethod","impl","neverPrint","alwaysBuffer","wrappedConsoleMethod","logType","clientName","bufferRef","historyLength","clientHistoryLength","filtered","concat","_toConsumableArray2","apply","stringified","item","_typeof2","returnItem","_stringify","_key","e","_console","toPrint","has","unshift","url","console","logDate","toISOString","repeat","deleteCount","splice","reason","forEach","impls","pop","prototype","client_logToBuffer","logToBuffer","_default2"],"sources":["logger.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {inBrowser, patterns} from '@webex/common';\nimport {WebexPlugin} from '@webex/webex-core';\nimport {cloneDeep, has, isArray, isObject, isString} from 'lodash';\n\nconst precedence = {\n silent: 0,\n group: 1,\n groupEnd: 2,\n error: 3,\n warn: 4,\n log: 5,\n info: 6,\n debug: 7,\n trace: 8,\n};\n\nexport const levels = Object.keys(precedence).filter((level) => level !== 'silent');\n\nconst fallbacks = {\n error: ['log'],\n warn: ['error', 'log'],\n info: ['log'],\n debug: ['info', 'log'],\n trace: ['debug', 'info', 'log'],\n};\n\nconst LOG_TYPES = {\n SDK: 'sdk',\n CLIENT: 'client',\n};\n\nconst SDK_LOG_TYPE_NAME = 'wx-js-sdk';\n\nconst authTokenKeyPattern = /[Aa]uthorization/;\n\n/**\n * Recursively strips \"authorization\" fields from the specified object\n * @param {Object} object\n * @param {Array<mixed>} [visited]\n * @private\n * @returns {Object}\n */\nfunction walkAndFilter(object, visited = []) {\n if (visited.includes(object)) {\n // Prevent circular references\n return object;\n }\n\n visited.push(object);\n\n if (isArray(object)) {\n return object.map((o) => walkAndFilter(o, visited));\n }\n if (!isObject(object)) {\n if (isString(object)) {\n if (patterns.containsEmails.test(object)) {\n return object.replace(patterns.containsEmails, '[REDACTED]');\n }\n if (patterns.containsMTID.test(object)) {\n return object.replace(patterns.containsMTID, '$1[REDACTED]');\n }\n }\n\n return object;\n }\n\n for (const [key, value] of Object.entries(object)) {\n if (authTokenKeyPattern.test(key)) {\n Reflect.deleteProperty(object, key);\n } else {\n object[key] = walkAndFilter(value, visited);\n }\n }\n\n return object;\n}\n\n/**\n * @class\n */\nconst Logger = WebexPlugin.extend({\n namespace: 'Logger',\n\n derived: {\n level: {\n cache: false,\n fn() {\n return this.getCurrentLevel();\n },\n },\n client_level: {\n cache: false,\n fn() {\n return this.getCurrentClientLevel();\n },\n },\n },\n session: {\n // for when configured to use single buffer\n buffer: {\n type: 'object',\n default() {\n return {\n buffer: [],\n nextIndex: 0,\n };\n },\n },\n groupLevel: {\n type: 'number',\n default() {\n return 0;\n },\n },\n // for when configured to use separate buffers\n sdkBuffer: {\n type: 'object',\n default() {\n return {\n buffer: [],\n nextIndex: 0,\n };\n },\n },\n clientBuffer: {\n type: 'object',\n default() {\n return {\n buffer: [],\n nextIndex: 0,\n };\n },\n },\n },\n\n /**\n * Ensures auth headers don't get printed in logs\n * @param {Array<mixed>} args\n * @private\n * @memberof Logger\n * @returns {Array<mixed>}\n */\n filter(...args) {\n return args.map((arg) => {\n // WebexHttpError already ensures auth tokens don't get printed, so, no\n // need to alter it here.\n if (arg instanceof Error) {\n // karma logs won't print subclassed errors correctly, so we need\n // explicitly call their tostring methods.\n if (process.env.NODE_ENV === 'test' && inBrowser) {\n let ret = arg.toString();\n\n ret += 'BEGIN STACK';\n ret += arg.stack;\n ret += 'END STACK';\n\n return ret;\n }\n\n return arg;\n }\n\n arg = cloneDeep(arg);\n\n return walkAndFilter(arg);\n });\n },\n\n /**\n * Determines if the current level allows logs at the specified level to be\n * printed\n * @param {string} level\n * @param {string} type type of log, SDK or client\n * @private\n * @memberof Logger\n * @returns {boolean}\n */\n shouldPrint(level, type = LOG_TYPES.SDK) {\n return (\n precedence[level] <=\n precedence[type === LOG_TYPES.SDK ? this.getCurrentLevel() : this.getCurrentClientLevel()]\n );\n },\n\n /**\n * Determines if the current level allows logs at the specified level to be\n * put into the log buffer. We're configuring it omit trace and debug logs\n * because there are *a lot* of debug logs that really don't provide value at\n * runtime (they're helpful for debugging locally, but really just pollute the\n * uploaded logs and push useful info out).\n * @param {string} level\n * @param {string} type type of log, SDK or client\n * @private\n * @memberof Logger\n * @returns {boolean}\n */\n shouldBuffer(level) {\n return (\n precedence[level] <=\n (this.config.bufferLogLevel ? precedence[this.config.bufferLogLevel] : precedence.info)\n );\n },\n\n /**\n * Indicates the current SDK log level based on env vars, feature toggles, and\n * user type.\n * @instance\n * @memberof Logger\n * @private\n * @memberof Logger\n * @returns {string}\n */\n // eslint-disable-next-line complexity\n getCurrentLevel() {\n // If a level has been explicitly set via config, alway use it.\n if (this.config.level) {\n return this.config.level;\n }\n\n if (levels.includes(process.env.WEBEX_LOG_LEVEL)) {\n return process.env.WEBEX_LOG_LEVEL;\n }\n\n // Always use debug-level logging in test mode;\n if (process.env.NODE_ENV === 'test') {\n return 'trace';\n }\n\n // Use server-side-feature toggles to configure log levels\n const level =\n this.webex.internal.device && this.webex.internal.device.features.developer.get('log-level');\n\n if (level) {\n if (levels.includes(level)) {\n return level;\n }\n }\n\n return 'error';\n },\n\n /**\n * Indicates the current client log level based on config, defaults to SDK level\n * @instance\n * @memberof Logger\n * @private\n * @memberof Logger\n * @returns {string}\n */\n getCurrentClientLevel() {\n // If a client log level has been explicitly set via config, alway use it.\n if (this.config.clientLevel) {\n return this.config.clientLevel;\n }\n\n // otherwise default to SDK level\n return this.getCurrentLevel();\n },\n\n /**\n * Format logs (for upload)\n *\n * If separate client, SDK buffers is configured, merge the buffers, if configured\n *\n * @instance\n * @memberof Logger\n * @public\n * @memberof Logger\n * @param {Object} options\n * @param {boolean} options.diff whether to only format the diff from last call to formatLogs(), false by default\n * @returns {string} formatted buffer\n */\n formatLogs(options = {}) {\n function getDate(log) {\n return log[1];\n }\n const {diff = false} = options;\n let buffer = [];\n let clientIndex = diff ? this.clientBuffer.nextIndex : 0;\n let sdkIndex = diff ? this.sdkBuffer.nextIndex : 0;\n\n if (this.config.separateLogBuffers) {\n // merge the client and sdk buffers\n // while we have entries in either buffer\n while (\n clientIndex < this.clientBuffer.buffer.length ||\n sdkIndex < this.sdkBuffer.buffer.length\n ) {\n // if we have remaining entries in the SDK buffer\n if (\n sdkIndex < this.sdkBuffer.buffer.length &&\n // and we haven't exhausted all the client buffer entries, or SDK date is before client date\n (clientIndex >= this.clientBuffer.buffer.length ||\n new Date(getDate(this.sdkBuffer.buffer[sdkIndex])) <=\n new Date(getDate(this.clientBuffer.buffer[clientIndex])))\n ) {\n // then add to the SDK buffer\n buffer.push(this.sdkBuffer.buffer[sdkIndex]);\n sdkIndex += 1;\n }\n // otherwise if we haven't exhausted all the client buffer entries, add client entry, whether it was because\n // it was the only remaining entries or date was later (the above if)\n else if (clientIndex < this.clientBuffer.buffer.length) {\n buffer.push(this.clientBuffer.buffer[clientIndex]);\n clientIndex += 1;\n }\n }\n if (diff) {\n this.clientBuffer.nextIndex = clientIndex;\n this.sdkBuffer.nextIndex = sdkIndex;\n }\n } else if (diff) {\n buffer = this.buffer.buffer.slice(this.buffer.nextIndex);\n this.buffer.nextIndex = this.buffer.buffer.length;\n } else {\n buffer = this.buffer.buffer;\n }\n\n return buffer.join('\\n');\n },\n});\n\n/**\n * Creates a logger method\n *\n *\n * @param {string} level level to create (info, error, warn, etc.)\n * @param {string} impl the level to use when writing to console\n * @param {string} type type of log, SDK or client\n * @param {bool} neverPrint function never prints to console\n * @param {bool} alwaysBuffer function always logs to log buffer\n * @instance\n * @memberof Logger\n * @private\n * @memberof Logger\n * @returns {function} logger method with specified params\n */\nfunction makeLoggerMethod(level, impl, type, neverPrint = false, alwaysBuffer = false) {\n // Much of the complexity in the following function is due to a test-mode-only\n // helper\n return function wrappedConsoleMethod(...args) {\n // it would be easier to just pass in the name and buffer here, but the config isn't completely initialized\n // in Ampersand, even if the initialize method is used to set this up. so we keep the type to achieve\n // a sort of late binding to allow retrieving a name from config.\n const logType = type;\n const clientName =\n logType === LOG_TYPES.SDK ? SDK_LOG_TYPE_NAME : this.config.clientName || logType;\n\n let bufferRef;\n let historyLength;\n\n if (this.config.separateLogBuffers) {\n historyLength = this.config.clientHistoryLength\n ? this.config.clientHistoryLength\n : this.config.historyLength;\n bufferRef = logType === LOG_TYPES.SDK ? this.sdkBuffer : this.clientBuffer;\n } else {\n bufferRef = this.buffer;\n historyLength = this.config.historyLength;\n }\n\n try {\n const shouldPrint = !neverPrint && this.shouldPrint(level, logType);\n const shouldBuffer = alwaysBuffer || this.shouldBuffer(level);\n\n if (!shouldBuffer && !shouldPrint) {\n return;\n }\n\n const filtered = [clientName, ...this.filter(...args)];\n const stringified = filtered.map((item) => {\n if (item instanceof Error) {\n return item.toString();\n }\n if (typeof item === 'object') {\n let cache = [];\n let returnItem;\n try {\n returnItem = JSON.stringify(item, (_key, value) => {\n if (typeof value === 'object' && value !== null) {\n if (cache.includes(value)) {\n // Circular reference found, discard key\n return undefined;\n }\n // Store value in our collection\n cache.push(value);\n }\n\n return value;\n });\n } catch (e) {\n returnItem = `Failed to stringify: ${item}`;\n }\n cache = null;\n\n return returnItem;\n }\n\n return item;\n });\n\n if (shouldPrint) {\n // when logging an object in browsers, we tend to get a dynamic\n // reference, thus going back to look at the logged value doesn't\n // necessarily show the state at log time, thus we print the stringified\n // value.\n const toPrint = inBrowser ? stringified : filtered;\n\n /* istanbul ignore if */\n if (process.env.NODE_ENV === 'test' && has(this, 'webex.internal.device.url')) {\n toPrint.unshift(this.webex.internal.device.url.slice(-3));\n }\n // eslint-disable-next-line no-console\n console[impl](...toPrint);\n }\n\n if (shouldBuffer) {\n const logDate = new Date();\n\n stringified.unshift(logDate.toISOString());\n stringified.unshift('| '.repeat(this.groupLevel));\n bufferRef.buffer.push(stringified);\n if (bufferRef.buffer.length > historyLength) {\n // we've gone over the buffer limit, trim it down\n const deleteCount = bufferRef.buffer.length - historyLength;\n\n bufferRef.buffer.splice(0, deleteCount);\n\n // and adjust the corresponding buffer index used for log diff uploads\n bufferRef.nextIndex -= deleteCount;\n if (bufferRef.nextIndex < 0) {\n bufferRef.nextIndex = 0;\n }\n }\n if (level === 'group') this.groupLevel += 1;\n if (level === 'groupEnd' && this.groupLevel > 0) this.groupLevel -= 1;\n }\n } catch (reason) {\n if (!neverPrint) {\n /* istanbul ignore next */\n // eslint-disable-next-line no-console\n console.warn(`failed to execute Logger#${level}`, reason);\n }\n }\n };\n}\n\nlevels.forEach((level) => {\n let impls = fallbacks[level];\n let impl = level;\n\n if (impls) {\n impls = impls.slice();\n // eslint-disable-next-line no-console\n while (!console[impl]) {\n impl = impls.pop();\n }\n }\n\n // eslint-disable-next-line complexity\n Logger.prototype[`client_${level}`] = makeLoggerMethod(level, impl, LOG_TYPES.CLIENT);\n Logger.prototype[level] = makeLoggerMethod(level, impl, LOG_TYPES.SDK);\n});\n\nLogger.prototype.client_logToBuffer = makeLoggerMethod(\n levels.info,\n levels.info,\n LOG_TYPES.CLIENT,\n true,\n true\n);\nLogger.prototype.logToBuffer = makeLoggerMethod(\n levels.info,\n levels.info,\n LOG_TYPES.SDK,\n true,\n true\n);\n\nexport default Logger;\n"],"mappings":";;;;;;;;;;;;;;;AAIA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AANA;AACA;AACA;;AAMA,IAAMG,UAAU,GAAG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E,CAAC,CAAC;AAEF8B,MAAM,CAAC2F,SAAS,CAACC,kBAAkB,GAAGrC,gBAAgB,CACpD7F,MAAM,CAACH,IAAI,EACXG,MAAM,CAACH,IAAI,EACXU,SAAS,CAACE,MAAM,EAChB,IAAI,EACJ,IACF,CAAC;AACD6B,MAAM,CAAC2F,SAAS,CAACE,WAAW,GAAGtC,gBAAgB,CAC7C7F,MAAM,CAACH,IAAI,EACXG,MAAM,CAACH,IAAI,EACXU,SAAS,CAACC,GAAG,EACb,IAAI,EACJ,IACF,CAAC;AAAC,IAAA4H,SAAA,GAAAnI,OAAA,CAAAE,OAAA,GAEamC,MAAM","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_common","require","_webexCore","_lodash","precedence","silent","group","groupEnd","error","warn","log","info","debug","trace","levels","exports","_keys","default","filter","level","fallbacks","LOG_TYPES","SDK","CLIENT","SDK_LOG_TYPE_NAME","authTokenKeyPattern","walkAndFilter","object","visited","arguments","length","undefined","includes","push","isArray","map","o","isObject","isString","patterns","containsEmails","test","replace","containsMTID","_i","_Object$entries","_entries","_Object$entries$_i","_slicedToArray2","key","value","_deleteProperty","Logger","WebexPlugin","extend","namespace","derived","cache","fn","getCurrentLevel","client_level","getCurrentClientLevel","session","buffer","type","nextIndex","lastSubmitted","groupLevel","sdkBuffer","clientBuffer","_len","args","Array","_key2","arg","Error","process","env","NODE_ENV","inBrowser","ret","toString","stack","cloneDeep","shouldPrint","shouldBuffer","config","bufferLogLevel","WEBEX_LOG_LEVEL","webex","internal","device","features","developer","get","clientLevel","formatLogs","options","getDate","_options$diff","diff","clientIndex","sdkIndex","separateLogBuffers","Date","slice","join","updateLastSubmittedIndex","resetBufferToLastSuccessfulUpload","version","makeLoggerMethod","impl","neverPrint","alwaysBuffer","wrappedConsoleMethod","logType","clientName","bufferRef","historyLength","clientHistoryLength","filtered","concat","_toConsumableArray2","apply","stringified","item","_typeof2","returnItem","_stringify","_key","e","_console","toPrint","has","unshift","url","console","logDate","toISOString","repeat","deleteCount","splice","reason","forEach","impls","pop","prototype","client_logToBuffer","logToBuffer","_default2"],"sources":["logger.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {inBrowser, patterns} from '@webex/common';\nimport {WebexPlugin} from '@webex/webex-core';\nimport {cloneDeep, has, isArray, isObject, isString} from 'lodash';\n\nconst precedence = {\n silent: 0,\n group: 1,\n groupEnd: 2,\n error: 3,\n warn: 4,\n log: 5,\n info: 6,\n debug: 7,\n trace: 8,\n};\n\nexport const levels = Object.keys(precedence).filter((level) => level !== 'silent');\n\nconst fallbacks = {\n error: ['log'],\n warn: ['error', 'log'],\n info: ['log'],\n debug: ['info', 'log'],\n trace: ['debug', 'info', 'log'],\n};\n\nconst LOG_TYPES = {\n SDK: 'sdk',\n CLIENT: 'client',\n};\n\nconst SDK_LOG_TYPE_NAME = 'wx-js-sdk';\n\nconst authTokenKeyPattern = /[Aa]uthorization/;\n\n/**\n * Recursively strips \"authorization\" fields from the specified object\n * @param {Object} object\n * @param {Array<mixed>} [visited]\n * @private\n * @returns {Object}\n */\nfunction walkAndFilter(object, visited = []) {\n if (visited.includes(object)) {\n // Prevent circular references\n return object;\n }\n\n visited.push(object);\n\n if (isArray(object)) {\n return object.map((o) => walkAndFilter(o, visited));\n }\n if (!isObject(object)) {\n if (isString(object)) {\n if (patterns.containsEmails.test(object)) {\n return object.replace(patterns.containsEmails, '[REDACTED]');\n }\n if (patterns.containsMTID.test(object)) {\n return object.replace(patterns.containsMTID, '$1[REDACTED]');\n }\n }\n\n return object;\n }\n\n for (const [key, value] of Object.entries(object)) {\n if (authTokenKeyPattern.test(key)) {\n Reflect.deleteProperty(object, key);\n } else {\n object[key] = walkAndFilter(value, visited);\n }\n }\n\n return object;\n}\n\n/**\n * @class\n */\nconst Logger = WebexPlugin.extend({\n namespace: 'Logger',\n\n derived: {\n level: {\n cache: false,\n fn() {\n return this.getCurrentLevel();\n },\n },\n client_level: {\n cache: false,\n fn() {\n return this.getCurrentClientLevel();\n },\n },\n },\n session: {\n // for when configured to use single buffer\n buffer: {\n type: 'object',\n default() {\n return {\n buffer: [],\n nextIndex: 0,\n lastSubmitted: 0,\n };\n },\n },\n groupLevel: {\n type: 'number',\n default() {\n return 0;\n },\n },\n // for when configured to use separate buffers\n sdkBuffer: {\n type: 'object',\n default() {\n return {\n buffer: [],\n nextIndex: 0,\n lastSubmitted: 0,\n };\n },\n },\n clientBuffer: {\n type: 'object',\n default() {\n return {\n buffer: [],\n nextIndex: 0,\n lastSubmitted: 0,\n };\n },\n },\n },\n\n /**\n * Ensures auth headers don't get printed in logs\n * @param {Array<mixed>} args\n * @private\n * @memberof Logger\n * @returns {Array<mixed>}\n */\n filter(...args) {\n return args.map((arg) => {\n // WebexHttpError already ensures auth tokens don't get printed, so, no\n // need to alter it here.\n if (arg instanceof Error) {\n // karma logs won't print subclassed errors correctly, so we need\n // explicitly call their tostring methods.\n if (process.env.NODE_ENV === 'test' && inBrowser) {\n let ret = arg.toString();\n\n ret += 'BEGIN STACK';\n ret += arg.stack;\n ret += 'END STACK';\n\n return ret;\n }\n\n return arg;\n }\n\n arg = cloneDeep(arg);\n\n return walkAndFilter(arg);\n });\n },\n\n /**\n * Determines if the current level allows logs at the specified level to be\n * printed\n * @param {string} level\n * @param {string} type type of log, SDK or client\n * @private\n * @memberof Logger\n * @returns {boolean}\n */\n shouldPrint(level, type = LOG_TYPES.SDK) {\n return (\n precedence[level] <=\n precedence[type === LOG_TYPES.SDK ? this.getCurrentLevel() : this.getCurrentClientLevel()]\n );\n },\n\n /**\n * Determines if the current level allows logs at the specified level to be\n * put into the log buffer. We're configuring it omit trace and debug logs\n * because there are *a lot* of debug logs that really don't provide value at\n * runtime (they're helpful for debugging locally, but really just pollute the\n * uploaded logs and push useful info out).\n * @param {string} level\n * @param {string} type type of log, SDK or client\n * @private\n * @memberof Logger\n * @returns {boolean}\n */\n shouldBuffer(level) {\n return (\n precedence[level] <=\n (this.config.bufferLogLevel ? precedence[this.config.bufferLogLevel] : precedence.info)\n );\n },\n\n /**\n * Indicates the current SDK log level based on env vars, feature toggles, and\n * user type.\n * @instance\n * @memberof Logger\n * @private\n * @memberof Logger\n * @returns {string}\n */\n // eslint-disable-next-line complexity\n getCurrentLevel() {\n // If a level has been explicitly set via config, alway use it.\n if (this.config.level) {\n return this.config.level;\n }\n\n if (levels.includes(process.env.WEBEX_LOG_LEVEL)) {\n return process.env.WEBEX_LOG_LEVEL;\n }\n\n // Always use debug-level logging in test mode;\n if (process.env.NODE_ENV === 'test') {\n return 'trace';\n }\n\n // Use server-side-feature toggles to configure log levels\n const level =\n this.webex.internal.device && this.webex.internal.device.features.developer.get('log-level');\n\n if (level) {\n if (levels.includes(level)) {\n return level;\n }\n }\n\n return 'error';\n },\n\n /**\n * Indicates the current client log level based on config, defaults to SDK level\n * @instance\n * @memberof Logger\n * @private\n * @memberof Logger\n * @returns {string}\n */\n getCurrentClientLevel() {\n // If a client log level has been explicitly set via config, alway use it.\n if (this.config.clientLevel) {\n return this.config.clientLevel;\n }\n\n // otherwise default to SDK level\n return this.getCurrentLevel();\n },\n\n /**\n * Format logs (for upload)\n *\n * If separate client, SDK buffers is configured, merge the buffers, if configured\n *\n * @instance\n * @memberof Logger\n * @public\n * @memberof Logger\n * @param {Object} options\n * @param {boolean} options.diff whether to only format the diff from last call to formatLogs(), false by default\n * @returns {string} formatted buffer\n */\n formatLogs(options = {}) {\n function getDate(log) {\n return log[1];\n }\n const {diff = false} = options;\n let buffer = [];\n let clientIndex = diff ? this.clientBuffer.nextIndex : 0;\n let sdkIndex = diff ? this.sdkBuffer.nextIndex : 0;\n\n if (this.config.separateLogBuffers) {\n // merge the client and sdk buffers\n // while we have entries in either buffer\n while (\n clientIndex < this.clientBuffer.buffer.length ||\n sdkIndex < this.sdkBuffer.buffer.length\n ) {\n // if we have remaining entries in the SDK buffer\n if (\n sdkIndex < this.sdkBuffer.buffer.length &&\n // and we haven't exhausted all the client buffer entries, or SDK date is before client date\n (clientIndex >= this.clientBuffer.buffer.length ||\n new Date(getDate(this.sdkBuffer.buffer[sdkIndex])) <=\n new Date(getDate(this.clientBuffer.buffer[clientIndex])))\n ) {\n // then add to the SDK buffer\n buffer.push(this.sdkBuffer.buffer[sdkIndex]);\n sdkIndex += 1;\n }\n // otherwise if we haven't exhausted all the client buffer entries, add client entry, whether it was because\n // it was the only remaining entries or date was later (the above if)\n else if (clientIndex < this.clientBuffer.buffer.length) {\n buffer.push(this.clientBuffer.buffer[clientIndex]);\n clientIndex += 1;\n }\n }\n if (diff) {\n this.clientBuffer.nextIndex = clientIndex;\n this.sdkBuffer.nextIndex = sdkIndex;\n }\n } else if (diff) {\n buffer = this.buffer.buffer.slice(this.buffer.nextIndex);\n this.buffer.nextIndex = this.buffer.buffer.length;\n } else {\n buffer = this.buffer.buffer;\n }\n\n return buffer.join('\\n');\n },\n\n /**\n * Update the last submitted index in the buffers to the current nextIndex\n *\n * @returns {void}\n */\n updateLastSubmittedIndex() {\n if (this.config.separateLogBuffers) {\n this.clientBuffer.lastSubmitted = this.clientBuffer.nextIndex;\n this.sdkBuffer.lastSubmitted = this.sdkBuffer.nextIndex;\n } else {\n this.buffer.lastSubmitted = this.buffer.nextIndex;\n }\n },\n\n /**\n * Reset the nextIndex in the buffers to the last successful upload index, effectively including any logs since the last successful upload in the next upload\n *\n * @returns {void}\n */\n resetBufferToLastSuccessfulUpload() {\n if (this.config.separateLogBuffers) {\n this.clientBuffer.nextIndex = this.clientBuffer.lastSubmitted;\n this.sdkBuffer.nextIndex = this.sdkBuffer.lastSubmitted;\n } else {\n this.buffer.nextIndex = this.buffer.lastSubmitted;\n }\n },\n});\n\n/**\n * Creates a logger method\n *\n *\n * @param {string} level level to create (info, error, warn, etc.)\n * @param {string} impl the level to use when writing to console\n * @param {string} type type of log, SDK or client\n * @param {bool} neverPrint function never prints to console\n * @param {bool} alwaysBuffer function always logs to log buffer\n * @instance\n * @memberof Logger\n * @private\n * @memberof Logger\n * @returns {function} logger method with specified params\n */\nfunction makeLoggerMethod(level, impl, type, neverPrint = false, alwaysBuffer = false) {\n // Much of the complexity in the following function is due to a test-mode-only\n // helper\n return function wrappedConsoleMethod(...args) {\n // it would be easier to just pass in the name and buffer here, but the config isn't completely initialized\n // in Ampersand, even if the initialize method is used to set this up. so we keep the type to achieve\n // a sort of late binding to allow retrieving a name from config.\n const logType = type;\n const clientName =\n logType === LOG_TYPES.SDK ? SDK_LOG_TYPE_NAME : this.config.clientName || logType;\n\n let bufferRef;\n let historyLength;\n\n if (this.config.separateLogBuffers) {\n historyLength = this.config.clientHistoryLength\n ? this.config.clientHistoryLength\n : this.config.historyLength;\n bufferRef = logType === LOG_TYPES.SDK ? this.sdkBuffer : this.clientBuffer;\n } else {\n bufferRef = this.buffer;\n historyLength = this.config.historyLength;\n }\n\n try {\n const shouldPrint = !neverPrint && this.shouldPrint(level, logType);\n const shouldBuffer = alwaysBuffer || this.shouldBuffer(level);\n\n if (!shouldBuffer && !shouldPrint) {\n return;\n }\n\n const filtered = [clientName, ...this.filter(...args)];\n const stringified = filtered.map((item) => {\n if (item instanceof Error) {\n return item.toString();\n }\n if (typeof item === 'object') {\n let cache = [];\n let returnItem;\n try {\n returnItem = JSON.stringify(item, (_key, value) => {\n if (typeof value === 'object' && value !== null) {\n if (cache.includes(value)) {\n // Circular reference found, discard key\n return undefined;\n }\n // Store value in our collection\n cache.push(value);\n }\n\n return value;\n });\n } catch (e) {\n returnItem = `Failed to stringify: ${item}`;\n }\n cache = null;\n\n return returnItem;\n }\n\n return item;\n });\n\n if (shouldPrint) {\n // when logging an object in browsers, we tend to get a dynamic\n // reference, thus going back to look at the logged value doesn't\n // necessarily show the state at log time, thus we print the stringified\n // value.\n const toPrint = inBrowser ? stringified : filtered;\n\n /* istanbul ignore if */\n if (process.env.NODE_ENV === 'test' && has(this, 'webex.internal.device.url')) {\n toPrint.unshift(this.webex.internal.device.url.slice(-3));\n }\n // eslint-disable-next-line no-console\n console[impl](...toPrint);\n }\n\n if (shouldBuffer) {\n const logDate = new Date();\n\n stringified.unshift(logDate.toISOString());\n stringified.unshift('| '.repeat(this.groupLevel));\n bufferRef.buffer.push(stringified);\n if (bufferRef.buffer.length > historyLength) {\n // we've gone over the buffer limit, trim it down\n const deleteCount = bufferRef.buffer.length - historyLength;\n\n bufferRef.buffer.splice(0, deleteCount);\n\n // and adjust the corresponding buffer index used for log diff uploads\n bufferRef.nextIndex -= deleteCount;\n if (bufferRef.nextIndex < 0) {\n bufferRef.nextIndex = 0;\n }\n\n bufferRef.lastSubmitted -= deleteCount;\n if (bufferRef.lastSubmitted < 0) {\n bufferRef.lastSubmitted = 0;\n }\n }\n if (level === 'group') this.groupLevel += 1;\n if (level === 'groupEnd' && this.groupLevel > 0) this.groupLevel -= 1;\n }\n } catch (reason) {\n if (!neverPrint) {\n /* istanbul ignore next */\n // eslint-disable-next-line no-console\n console.warn(`failed to execute Logger#${level}`, reason);\n }\n }\n };\n}\n\nlevels.forEach((level) => {\n let impls = fallbacks[level];\n let impl = level;\n\n if (impls) {\n impls = impls.slice();\n // eslint-disable-next-line no-console\n while (!console[impl]) {\n impl = impls.pop();\n }\n }\n\n // eslint-disable-next-line complexity\n Logger.prototype[`client_${level}`] = makeLoggerMethod(level, impl, LOG_TYPES.CLIENT);\n Logger.prototype[level] = makeLoggerMethod(level, impl, LOG_TYPES.SDK);\n});\n\nLogger.prototype.client_logToBuffer = makeLoggerMethod(\n levels.info,\n levels.info,\n LOG_TYPES.CLIENT,\n true,\n true\n);\nLogger.prototype.logToBuffer = makeLoggerMethod(\n levels.info,\n levels.info,\n LOG_TYPES.SDK,\n true,\n true\n);\n\nexport default Logger;\n"],"mappings":";;;;;;;;;;;;;;;AAIA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AANA;AACA;AACA;;AAMA,IAAMG,UAAU,GAAG;EACjBC,MAAM,EAAE,CAAC;EACTC,KA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AAG,EACb,IAAI,EACJ,IACF,CAAC;AAAC,IAAA+H,SAAA,GAAAtI,OAAA,CAAAE,OAAA,GAEamC,MAAM","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -24,20 +24,20 @@
|
|
|
24
24
|
"@webex/eslint-config-legacy": "0.0.0",
|
|
25
25
|
"@webex/jest-config-legacy": "0.0.0",
|
|
26
26
|
"@webex/legacy-tools": "0.0.0",
|
|
27
|
-
"@webex/test-helper-chai": "3.12.0-
|
|
28
|
-
"@webex/test-helper-mocha": "3.12.0-
|
|
29
|
-
"@webex/test-helper-mock-webex": "3.12.0-
|
|
30
|
-
"@webex/test-helper-test-users": "3.12.0-
|
|
27
|
+
"@webex/test-helper-chai": "3.12.0-webex-services-ready.1",
|
|
28
|
+
"@webex/test-helper-mocha": "3.12.0-webex-services-ready.1",
|
|
29
|
+
"@webex/test-helper-mock-webex": "3.12.0-webex-services-ready.1",
|
|
30
|
+
"@webex/test-helper-test-users": "3.12.0-webex-services-ready.1",
|
|
31
31
|
"eslint": "^8.24.0",
|
|
32
32
|
"prettier": "^2.7.1",
|
|
33
33
|
"sinon": "^9.2.4"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@webex/common": "3.12.0-
|
|
37
|
-
"@webex/test-helper-chai": "3.12.0-
|
|
38
|
-
"@webex/test-helper-mocha": "3.12.0-
|
|
39
|
-
"@webex/test-helper-mock-webex": "3.12.0-
|
|
40
|
-
"@webex/webex-core": "3.12.0-
|
|
36
|
+
"@webex/common": "3.12.0-webex-services-ready.1",
|
|
37
|
+
"@webex/test-helper-chai": "3.12.0-webex-services-ready.1",
|
|
38
|
+
"@webex/test-helper-mocha": "3.12.0-webex-services-ready.1",
|
|
39
|
+
"@webex/test-helper-mock-webex": "3.12.0-webex-services-ready.1",
|
|
40
|
+
"@webex/webex-core": "3.12.0-webex-services-ready.1",
|
|
41
41
|
"lodash": "^4.17.21"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"test:style": "eslint ./src/**/*.*",
|
|
50
50
|
"test:unit": "webex-legacy-tools test --unit --runner jest"
|
|
51
51
|
},
|
|
52
|
-
"version": "3.12.0-
|
|
52
|
+
"version": "3.12.0-webex-services-ready.1"
|
|
53
53
|
}
|
package/src/logger.js
CHANGED
|
@@ -107,6 +107,7 @@ const Logger = WebexPlugin.extend({
|
|
|
107
107
|
return {
|
|
108
108
|
buffer: [],
|
|
109
109
|
nextIndex: 0,
|
|
110
|
+
lastSubmitted: 0,
|
|
110
111
|
};
|
|
111
112
|
},
|
|
112
113
|
},
|
|
@@ -123,6 +124,7 @@ const Logger = WebexPlugin.extend({
|
|
|
123
124
|
return {
|
|
124
125
|
buffer: [],
|
|
125
126
|
nextIndex: 0,
|
|
127
|
+
lastSubmitted: 0,
|
|
126
128
|
};
|
|
127
129
|
},
|
|
128
130
|
},
|
|
@@ -132,6 +134,7 @@ const Logger = WebexPlugin.extend({
|
|
|
132
134
|
return {
|
|
133
135
|
buffer: [],
|
|
134
136
|
nextIndex: 0,
|
|
137
|
+
lastSubmitted: 0,
|
|
135
138
|
};
|
|
136
139
|
},
|
|
137
140
|
},
|
|
@@ -322,6 +325,34 @@ const Logger = WebexPlugin.extend({
|
|
|
322
325
|
|
|
323
326
|
return buffer.join('\n');
|
|
324
327
|
},
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Update the last submitted index in the buffers to the current nextIndex
|
|
331
|
+
*
|
|
332
|
+
* @returns {void}
|
|
333
|
+
*/
|
|
334
|
+
updateLastSubmittedIndex() {
|
|
335
|
+
if (this.config.separateLogBuffers) {
|
|
336
|
+
this.clientBuffer.lastSubmitted = this.clientBuffer.nextIndex;
|
|
337
|
+
this.sdkBuffer.lastSubmitted = this.sdkBuffer.nextIndex;
|
|
338
|
+
} else {
|
|
339
|
+
this.buffer.lastSubmitted = this.buffer.nextIndex;
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Reset the nextIndex in the buffers to the last successful upload index, effectively including any logs since the last successful upload in the next upload
|
|
345
|
+
*
|
|
346
|
+
* @returns {void}
|
|
347
|
+
*/
|
|
348
|
+
resetBufferToLastSuccessfulUpload() {
|
|
349
|
+
if (this.config.separateLogBuffers) {
|
|
350
|
+
this.clientBuffer.nextIndex = this.clientBuffer.lastSubmitted;
|
|
351
|
+
this.sdkBuffer.nextIndex = this.sdkBuffer.lastSubmitted;
|
|
352
|
+
} else {
|
|
353
|
+
this.buffer.nextIndex = this.buffer.lastSubmitted;
|
|
354
|
+
}
|
|
355
|
+
},
|
|
325
356
|
});
|
|
326
357
|
|
|
327
358
|
/**
|
|
@@ -435,6 +466,11 @@ function makeLoggerMethod(level, impl, type, neverPrint = false, alwaysBuffer =
|
|
|
435
466
|
if (bufferRef.nextIndex < 0) {
|
|
436
467
|
bufferRef.nextIndex = 0;
|
|
437
468
|
}
|
|
469
|
+
|
|
470
|
+
bufferRef.lastSubmitted -= deleteCount;
|
|
471
|
+
if (bufferRef.lastSubmitted < 0) {
|
|
472
|
+
bufferRef.lastSubmitted = 0;
|
|
473
|
+
}
|
|
438
474
|
}
|
|
439
475
|
if (level === 'group') this.groupLevel += 1;
|
|
440
476
|
if (level === 'groupEnd' && this.groupLevel > 0) this.groupLevel -= 1;
|
package/test/unit/spec/logger.js
CHANGED
|
@@ -128,6 +128,69 @@ describe('plugin-logger', () => {
|
|
|
128
128
|
assert.equal(webex.logger.buffer.buffer[1][3], 3);
|
|
129
129
|
});
|
|
130
130
|
|
|
131
|
+
it('adjusts lastSubmitted when buffer overflows in single buffer mode', () => {
|
|
132
|
+
webex.config.logger.historyLength = 3;
|
|
133
|
+
|
|
134
|
+
webex.logger.log('a');
|
|
135
|
+
webex.logger.log('b');
|
|
136
|
+
|
|
137
|
+
// simulate a successful upload
|
|
138
|
+
webex.logger.formatLogs({diff: true});
|
|
139
|
+
webex.logger.updateLastSubmittedIndex();
|
|
140
|
+
assert.equal(webex.logger.buffer.lastSubmitted, 2);
|
|
141
|
+
|
|
142
|
+
// add more logs to trigger overflow
|
|
143
|
+
webex.logger.log('c');
|
|
144
|
+
webex.logger.log('d');
|
|
145
|
+
|
|
146
|
+
// buffer overflowed by 1, so lastSubmitted should be decremented by 1
|
|
147
|
+
assert.equal(webex.logger.buffer.lastSubmitted, 1);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('clamps lastSubmitted to 0 when buffer overflow exceeds lastSubmitted in single buffer mode', () => {
|
|
151
|
+
webex.config.logger.historyLength = 2;
|
|
152
|
+
|
|
153
|
+
webex.logger.log('a');
|
|
154
|
+
|
|
155
|
+
// simulate a successful upload after just 1 log
|
|
156
|
+
webex.logger.formatLogs({diff: true});
|
|
157
|
+
webex.logger.updateLastSubmittedIndex();
|
|
158
|
+
assert.equal(webex.logger.buffer.lastSubmitted, 1);
|
|
159
|
+
|
|
160
|
+
// add enough logs to overflow past the lastSubmitted value
|
|
161
|
+
webex.logger.log('b');
|
|
162
|
+
webex.logger.log('c');
|
|
163
|
+
webex.logger.log('d');
|
|
164
|
+
|
|
165
|
+
assert.equal(webex.logger.buffer.lastSubmitted, 0);
|
|
166
|
+
assert.lengthOf(webex.logger.buffer.buffer, 2);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('adjusts lastSubmitted when buffer overflows in separate buffer mode', () => {
|
|
170
|
+
webex.config.logger.separateLogBuffers = true;
|
|
171
|
+
webex.config.logger.clientName = 'someclient';
|
|
172
|
+
webex.config.logger.historyLength = 3;
|
|
173
|
+
|
|
174
|
+
webex.logger.log('sdk1');
|
|
175
|
+
webex.logger.log('sdk2');
|
|
176
|
+
webex.logger.client_log('client1');
|
|
177
|
+
webex.logger.client_log('client2');
|
|
178
|
+
|
|
179
|
+
webex.logger.formatLogs({diff: true});
|
|
180
|
+
webex.logger.updateLastSubmittedIndex();
|
|
181
|
+
assert.equal(webex.logger.sdkBuffer.lastSubmitted, 2);
|
|
182
|
+
assert.equal(webex.logger.clientBuffer.lastSubmitted, 2);
|
|
183
|
+
|
|
184
|
+
// overflow both buffers by 1
|
|
185
|
+
webex.logger.log('sdk3');
|
|
186
|
+
webex.logger.log('sdk4');
|
|
187
|
+
webex.logger.client_log('client3');
|
|
188
|
+
webex.logger.client_log('client4');
|
|
189
|
+
|
|
190
|
+
assert.equal(webex.logger.sdkBuffer.lastSubmitted, 1);
|
|
191
|
+
assert.equal(webex.logger.clientBuffer.lastSubmitted, 1);
|
|
192
|
+
});
|
|
193
|
+
|
|
131
194
|
it('prevents the client and sdk buffer from overflowing', () => {
|
|
132
195
|
webex.config.logger.historyLength = 2;
|
|
133
196
|
webex.config.logger.separateLogBuffers = true;
|
|
@@ -196,8 +259,8 @@ describe('plugin-logger', () => {
|
|
|
196
259
|
test: 'object',
|
|
197
260
|
nested: {
|
|
198
261
|
test2: 'object2',
|
|
199
|
-
}
|
|
200
|
-
}
|
|
262
|
+
},
|
|
263
|
+
};
|
|
201
264
|
|
|
202
265
|
webex.logger.log('foo', 'bar', obj);
|
|
203
266
|
assert.lengthOf(webex.logger.buffer.buffer, 1);
|
|
@@ -205,7 +268,10 @@ describe('plugin-logger', () => {
|
|
|
205
268
|
assert.deepEqual(webex.logger.buffer.buffer[0][2], 'wx-js-sdk');
|
|
206
269
|
assert.deepEqual(webex.logger.buffer.buffer[0][3], 'foo');
|
|
207
270
|
assert.deepEqual(webex.logger.buffer.buffer[0][4], 'bar');
|
|
208
|
-
assert.deepEqual(
|
|
271
|
+
assert.deepEqual(
|
|
272
|
+
webex.logger.buffer.buffer[0][5],
|
|
273
|
+
'{"headers":{"trackingid":"123"},"test":"object","nested":{"test2":"object2"}}'
|
|
274
|
+
);
|
|
209
275
|
});
|
|
210
276
|
|
|
211
277
|
it('formats objects as strings passed to the logger for readability not [Object object] w/ circular reference', async () => {
|
|
@@ -218,8 +284,8 @@ describe('plugin-logger', () => {
|
|
|
218
284
|
test: 'object',
|
|
219
285
|
nested: {
|
|
220
286
|
test2: 'object2',
|
|
221
|
-
}
|
|
222
|
-
}
|
|
287
|
+
},
|
|
288
|
+
};
|
|
223
289
|
|
|
224
290
|
obj.selfReference = obj;
|
|
225
291
|
|
|
@@ -229,19 +295,21 @@ describe('plugin-logger', () => {
|
|
|
229
295
|
assert.deepEqual(webex.logger.buffer.buffer[0][2], 'wx-js-sdk');
|
|
230
296
|
assert.deepEqual(webex.logger.buffer.buffer[0][3], 'foo');
|
|
231
297
|
assert.deepEqual(webex.logger.buffer.buffer[0][4], 'bar');
|
|
232
|
-
assert.deepEqual(
|
|
298
|
+
assert.deepEqual(
|
|
299
|
+
webex.logger.buffer.buffer[0][5],
|
|
300
|
+
'{"headers":{"trackingid":"123"},"test":"object","nested":{"test2":"object2"}}'
|
|
301
|
+
);
|
|
233
302
|
});
|
|
234
303
|
|
|
235
304
|
it('formats Errors correctly', async () => {
|
|
236
305
|
webex.config.logger.level = 'trace';
|
|
237
|
-
const err = new Error('fake error for testing')
|
|
306
|
+
const err = new Error('fake error for testing');
|
|
238
307
|
|
|
239
308
|
webex.logger.log('I got this error:', err);
|
|
240
309
|
assert.lengthOf(webex.logger.buffer.buffer, 1);
|
|
241
310
|
assert.deepEqual(webex.logger.buffer.buffer[0][2], 'wx-js-sdk');
|
|
242
311
|
assert.deepEqual(webex.logger.buffer.buffer[0][3], 'I got this error:');
|
|
243
312
|
assert.deepEqual(webex.logger.buffer.buffer[0][4], 'Error: fake error for testing');
|
|
244
|
-
|
|
245
313
|
});
|
|
246
314
|
});
|
|
247
315
|
|
|
@@ -649,12 +717,16 @@ describe('plugin-logger', () => {
|
|
|
649
717
|
},
|
|
650
718
|
});
|
|
651
719
|
|
|
652
|
-
if(inBrowser()) {
|
|
653
|
-
assert.calledWith(
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
720
|
+
if (inBrowser()) {
|
|
721
|
+
assert.calledWith(
|
|
722
|
+
console[impl(level)],
|
|
723
|
+
'wx-js-sdk',
|
|
724
|
+
JSON.stringify({
|
|
725
|
+
headers: {
|
|
726
|
+
trackingid: '123',
|
|
727
|
+
},
|
|
728
|
+
})
|
|
729
|
+
);
|
|
658
730
|
} else {
|
|
659
731
|
assert.calledWith(console[impl(level)], 'wx-js-sdk', {
|
|
660
732
|
headers: {
|
|
@@ -676,24 +748,23 @@ describe('plugin-logger', () => {
|
|
|
676
748
|
|
|
677
749
|
// Assert auth was filtered
|
|
678
750
|
|
|
679
|
-
if(inBrowser()) {
|
|
680
|
-
assert.calledWith(console.log,
|
|
751
|
+
if (inBrowser()) {
|
|
752
|
+
assert.calledWith(console.log, 'wx-js-sdk', JSON.stringify({Key: 'myKey'}));
|
|
681
753
|
} else {
|
|
682
|
-
assert.calledWith(console.log,
|
|
754
|
+
assert.calledWith(console.log, 'wx-js-sdk', {Key: 'myKey'});
|
|
683
755
|
}
|
|
684
|
-
|
|
756
|
+
webex.logger.log({
|
|
685
757
|
authorization: 'XXXXXXX',
|
|
686
758
|
Key: 'myKey',
|
|
687
759
|
});
|
|
688
|
-
9
|
|
689
|
-
|
|
690
|
-
if(inBrowser()) {
|
|
691
|
-
assert.calledWith(console.log, "wx-js-sdk", JSON.stringify({Key: 'myKey'}));
|
|
760
|
+
9;
|
|
692
761
|
|
|
762
|
+
if (inBrowser()) {
|
|
763
|
+
assert.calledWith(console.log, 'wx-js-sdk', JSON.stringify({Key: 'myKey'}));
|
|
693
764
|
} else {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
765
|
+
assert.calledWith(console.log, 'wx-js-sdk', {Key: 'myKey'});
|
|
766
|
+
}
|
|
767
|
+
});
|
|
697
768
|
|
|
698
769
|
it('redact emails', () => {
|
|
699
770
|
webex.config.logger.level = 'trace';
|
|
@@ -708,21 +779,42 @@ describe('plugin-logger', () => {
|
|
|
708
779
|
it('redact MTID', () => {
|
|
709
780
|
webex.config.logger.level = 'trace';
|
|
710
781
|
|
|
711
|
-
const destination =
|
|
782
|
+
const destination =
|
|
783
|
+
'https://example.com/example/j.php?MTID=m678957bc1eff989c2176b43ead9d46b5';
|
|
712
784
|
|
|
713
|
-
webex.logger.log(
|
|
714
|
-
|
|
785
|
+
webex.logger.log(`Info Unable to fetch meeting info for ${destination}.`);
|
|
786
|
+
assert.calledWith(
|
|
787
|
+
console.log,
|
|
788
|
+
'wx-js-sdk',
|
|
789
|
+
'Info Unable to fetch meeting info for https://example.com/example/j.php?MTID=[REDACTED]'
|
|
715
790
|
);
|
|
716
|
-
assert.calledWith(console.log, 'wx-js-sdk', 'Info Unable to fetch meeting info for https://example.com/example/j.php?MTID=[REDACTED]');
|
|
717
791
|
|
|
718
|
-
webex.logger.log(
|
|
719
|
-
|
|
792
|
+
webex.logger.log(
|
|
793
|
+
'https://example.com/example/j.php?MTID=m678957bc1eff989c2176b43ead9d46b5&abcdefg'
|
|
794
|
+
);
|
|
795
|
+
assert.calledWith(
|
|
796
|
+
console.log,
|
|
797
|
+
'wx-js-sdk',
|
|
798
|
+
'https://example.com/example/j.php?MTID=[REDACTED]&abcdefg'
|
|
799
|
+
);
|
|
720
800
|
|
|
721
|
-
webex.logger.log(
|
|
722
|
-
|
|
801
|
+
webex.logger.log(
|
|
802
|
+
'https://example.com/example/j.php?MTID=m678957bc1eff989c2176b43ead9d46b5$abcdefg'
|
|
803
|
+
);
|
|
804
|
+
assert.calledWith(
|
|
805
|
+
console.log,
|
|
806
|
+
'wx-js-sdk',
|
|
807
|
+
'https://example.com/example/j.php?MTID=[REDACTED]$abcdefg'
|
|
808
|
+
);
|
|
723
809
|
|
|
724
|
-
webex.logger.log(
|
|
725
|
-
|
|
810
|
+
webex.logger.log(
|
|
811
|
+
'https://example.com/example/j.php?MTID=m678957bc1eff989c2176b43ead9d46b5#abcdefg'
|
|
812
|
+
);
|
|
813
|
+
assert.calledWith(
|
|
814
|
+
console.log,
|
|
815
|
+
'wx-js-sdk',
|
|
816
|
+
'https://example.com/example/j.php?MTID=[REDACTED]#abcdefg'
|
|
817
|
+
);
|
|
726
818
|
});
|
|
727
819
|
|
|
728
820
|
nodeOnly(it)('handle circular references', () => {
|
|
@@ -744,17 +836,15 @@ describe('plugin-logger', () => {
|
|
|
744
836
|
Key: 'myKey',
|
|
745
837
|
};
|
|
746
838
|
|
|
747
|
-
// Has self reference which is bad
|
|
839
|
+
// Has self reference which is bad
|
|
748
840
|
expected.selfReference = expected;
|
|
749
841
|
|
|
750
|
-
if(inBrowser()) {
|
|
751
|
-
assert.calledWith(console.log,
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
}
|
|
757
|
-
});
|
|
842
|
+
if (inBrowser()) {
|
|
843
|
+
assert.calledWith(console.log, 'wx-js-sdk', JSON.stringify(expected));
|
|
844
|
+
} else {
|
|
845
|
+
assert.calledWith(console.log, 'wx-js-sdk', expected);
|
|
846
|
+
}
|
|
847
|
+
});
|
|
758
848
|
|
|
759
849
|
nodeOnly(it)('handle circular references in complex objects', () => {
|
|
760
850
|
webex.config.logger.level = 'trace';
|
|
@@ -802,18 +892,15 @@ describe('plugin-logger', () => {
|
|
|
802
892
|
circularObjectRef: object,
|
|
803
893
|
circularFunctionRef: func,
|
|
804
894
|
},
|
|
805
|
-
}
|
|
806
|
-
|
|
895
|
+
};
|
|
807
896
|
|
|
808
|
-
if(inBrowser()) {
|
|
809
|
-
assert.calledWith(console.log,
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
}
|
|
815
|
-
});
|
|
897
|
+
if (inBrowser()) {
|
|
898
|
+
assert.calledWith(console.log, 'wx-js-sdk', JSON.stringify(res));
|
|
899
|
+
} else {
|
|
900
|
+
assert.calledWith(console.log, 'wx-js-sdk', res);
|
|
901
|
+
}
|
|
816
902
|
});
|
|
903
|
+
});
|
|
817
904
|
|
|
818
905
|
describe('#formatLogs()', () => {
|
|
819
906
|
function sendRandomLog(log) {
|
|
@@ -1265,4 +1352,181 @@ describe('plugin-logger', () => {
|
|
|
1265
1352
|
assert.lengthOf(webex.logger.buffer.buffer, 5);
|
|
1266
1353
|
});
|
|
1267
1354
|
});
|
|
1355
|
+
|
|
1356
|
+
describe('#updateLastSubmittedIndex()', () => {
|
|
1357
|
+
let clock;
|
|
1358
|
+
|
|
1359
|
+
beforeEach(() => {
|
|
1360
|
+
clock = sinon.useFakeTimers();
|
|
1361
|
+
});
|
|
1362
|
+
|
|
1363
|
+
afterEach(() => {
|
|
1364
|
+
clock.restore();
|
|
1365
|
+
});
|
|
1366
|
+
|
|
1367
|
+
it('updates lastSubmitted to the current nextIndex in single buffer mode', () => {
|
|
1368
|
+
webex.config.logger.separateLogBuffers = false;
|
|
1369
|
+
|
|
1370
|
+
webex.logger.log('a');
|
|
1371
|
+
clock.tick(1000);
|
|
1372
|
+
webex.logger.log('b');
|
|
1373
|
+
clock.tick(1000);
|
|
1374
|
+
|
|
1375
|
+
// advance nextIndex by consuming a diff
|
|
1376
|
+
webex.logger.formatLogs({diff: true});
|
|
1377
|
+
const nextIndexAfterDiff = webex.logger.buffer.nextIndex;
|
|
1378
|
+
|
|
1379
|
+
assert.equal(webex.logger.buffer.lastSubmitted, 0);
|
|
1380
|
+
|
|
1381
|
+
webex.logger.updateLastSubmittedIndex();
|
|
1382
|
+
|
|
1383
|
+
assert.equal(webex.logger.buffer.lastSubmitted, nextIndexAfterDiff);
|
|
1384
|
+
});
|
|
1385
|
+
|
|
1386
|
+
it('updates lastSubmitted to the current nextIndex in separate buffer mode', () => {
|
|
1387
|
+
webex.config.logger.separateLogBuffers = true;
|
|
1388
|
+
webex.config.logger.clientName = 'someclient';
|
|
1389
|
+
|
|
1390
|
+
webex.logger.log('sdk1');
|
|
1391
|
+
clock.tick(1000);
|
|
1392
|
+
webex.logger.client_log('client1');
|
|
1393
|
+
clock.tick(1000);
|
|
1394
|
+
|
|
1395
|
+
webex.logger.formatLogs({diff: true});
|
|
1396
|
+
const sdkNextIndex = webex.logger.sdkBuffer.nextIndex;
|
|
1397
|
+
const clientNextIndex = webex.logger.clientBuffer.nextIndex;
|
|
1398
|
+
|
|
1399
|
+
assert.equal(webex.logger.sdkBuffer.lastSubmitted, 0);
|
|
1400
|
+
assert.equal(webex.logger.clientBuffer.lastSubmitted, 0);
|
|
1401
|
+
|
|
1402
|
+
webex.logger.updateLastSubmittedIndex();
|
|
1403
|
+
|
|
1404
|
+
assert.equal(webex.logger.sdkBuffer.lastSubmitted, sdkNextIndex);
|
|
1405
|
+
assert.equal(webex.logger.clientBuffer.lastSubmitted, clientNextIndex);
|
|
1406
|
+
});
|
|
1407
|
+
|
|
1408
|
+
it('stores lastSubmitted as 0 when no diff has been consumed yet in single buffer mode', () => {
|
|
1409
|
+
webex.config.logger.separateLogBuffers = false;
|
|
1410
|
+
|
|
1411
|
+
webex.logger.log('a');
|
|
1412
|
+
webex.logger.updateLastSubmittedIndex();
|
|
1413
|
+
|
|
1414
|
+
// nextIndex is still 0 because no diff was consumed
|
|
1415
|
+
assert.equal(webex.logger.buffer.lastSubmitted, webex.logger.buffer.nextIndex);
|
|
1416
|
+
});
|
|
1417
|
+
});
|
|
1418
|
+
|
|
1419
|
+
describe('#resetBufferToLastSuccessfulUpload()', () => {
|
|
1420
|
+
let clock;
|
|
1421
|
+
|
|
1422
|
+
beforeEach(() => {
|
|
1423
|
+
clock = sinon.useFakeTimers();
|
|
1424
|
+
});
|
|
1425
|
+
|
|
1426
|
+
afterEach(() => {
|
|
1427
|
+
clock.restore();
|
|
1428
|
+
});
|
|
1429
|
+
|
|
1430
|
+
it('resets nextIndex to lastSubmitted in single buffer mode', () => {
|
|
1431
|
+
webex.config.logger.separateLogBuffers = false;
|
|
1432
|
+
|
|
1433
|
+
webex.logger.log('a');
|
|
1434
|
+
clock.tick(1000);
|
|
1435
|
+
webex.logger.log('b');
|
|
1436
|
+
clock.tick(1000);
|
|
1437
|
+
|
|
1438
|
+
// simulate a successful upload: consume diff then mark as submitted
|
|
1439
|
+
webex.logger.formatLogs({diff: true});
|
|
1440
|
+
webex.logger.updateLastSubmittedIndex();
|
|
1441
|
+
const submittedIndex = webex.logger.buffer.lastSubmitted;
|
|
1442
|
+
|
|
1443
|
+
// log more entries (simulating logs added after the upload)
|
|
1444
|
+
webex.logger.log('c');
|
|
1445
|
+
clock.tick(1000);
|
|
1446
|
+
webex.logger.formatLogs({diff: true});
|
|
1447
|
+
assert.isAbove(webex.logger.buffer.nextIndex, submittedIndex);
|
|
1448
|
+
|
|
1449
|
+
// simulate upload failure — reset so the next diff re-includes logs since last success
|
|
1450
|
+
webex.logger.resetBufferToLastSuccessfulUpload();
|
|
1451
|
+
|
|
1452
|
+
assert.equal(webex.logger.buffer.nextIndex, submittedIndex);
|
|
1453
|
+
});
|
|
1454
|
+
|
|
1455
|
+
it('resets nextIndex to lastSubmitted in separate buffer mode', () => {
|
|
1456
|
+
webex.config.logger.separateLogBuffers = true;
|
|
1457
|
+
webex.config.logger.clientName = 'someclient';
|
|
1458
|
+
|
|
1459
|
+
webex.logger.log('sdk1');
|
|
1460
|
+
clock.tick(1000);
|
|
1461
|
+
webex.logger.client_log('client1');
|
|
1462
|
+
clock.tick(1000);
|
|
1463
|
+
|
|
1464
|
+
webex.logger.formatLogs({diff: true});
|
|
1465
|
+
webex.logger.updateLastSubmittedIndex();
|
|
1466
|
+
const submittedSdk = webex.logger.sdkBuffer.lastSubmitted;
|
|
1467
|
+
const submittedClient = webex.logger.clientBuffer.lastSubmitted;
|
|
1468
|
+
|
|
1469
|
+
webex.logger.log('sdk2');
|
|
1470
|
+
clock.tick(1000);
|
|
1471
|
+
webex.logger.client_log('client2');
|
|
1472
|
+
clock.tick(1000);
|
|
1473
|
+
webex.logger.formatLogs({diff: true});
|
|
1474
|
+
|
|
1475
|
+
assert.isAbove(webex.logger.sdkBuffer.nextIndex, submittedSdk);
|
|
1476
|
+
assert.isAbove(webex.logger.clientBuffer.nextIndex, submittedClient);
|
|
1477
|
+
|
|
1478
|
+
webex.logger.resetBufferToLastSuccessfulUpload();
|
|
1479
|
+
|
|
1480
|
+
assert.equal(webex.logger.sdkBuffer.nextIndex, submittedSdk);
|
|
1481
|
+
assert.equal(webex.logger.clientBuffer.nextIndex, submittedClient);
|
|
1482
|
+
});
|
|
1483
|
+
|
|
1484
|
+
it('causes the next diff to re-include logs since the last successful upload', () => {
|
|
1485
|
+
webex.config.logger.separateLogBuffers = false;
|
|
1486
|
+
|
|
1487
|
+
webex.logger.log('a');
|
|
1488
|
+
clock.tick(1000);
|
|
1489
|
+
webex.logger.log('b');
|
|
1490
|
+
clock.tick(1000);
|
|
1491
|
+
|
|
1492
|
+
// first successful upload
|
|
1493
|
+
const diff1 = webex.logger.formatLogs({diff: true});
|
|
1494
|
+
|
|
1495
|
+
assert.deepEqual(diff1.split('\n'), [
|
|
1496
|
+
',1970-01-01T00:00:00.000Z,wx-js-sdk,a',
|
|
1497
|
+
',1970-01-01T00:00:01.000Z,wx-js-sdk,b',
|
|
1498
|
+
]);
|
|
1499
|
+
webex.logger.updateLastSubmittedIndex();
|
|
1500
|
+
|
|
1501
|
+
// new logs arrive
|
|
1502
|
+
webex.logger.log('c');
|
|
1503
|
+
clock.tick(1000);
|
|
1504
|
+
|
|
1505
|
+
// consume the diff (upload attempt that fails)
|
|
1506
|
+
const diff2 = webex.logger.formatLogs({diff: true});
|
|
1507
|
+
|
|
1508
|
+
assert.deepEqual(diff2.split('\n'), [',1970-01-01T00:00:02.000Z,wx-js-sdk,c']);
|
|
1509
|
+
|
|
1510
|
+
// upload failed — roll back
|
|
1511
|
+
webex.logger.resetBufferToLastSuccessfulUpload();
|
|
1512
|
+
|
|
1513
|
+
// retry: should get 'c' again
|
|
1514
|
+
const diff3 = webex.logger.formatLogs({diff: true});
|
|
1515
|
+
|
|
1516
|
+
assert.deepEqual(diff3.split('\n'), [',1970-01-01T00:00:02.000Z,wx-js-sdk,c']);
|
|
1517
|
+
});
|
|
1518
|
+
|
|
1519
|
+
it('resets nextIndex to 0 when updateLastSubmittedIndex was never called', () => {
|
|
1520
|
+
webex.config.logger.separateLogBuffers = false;
|
|
1521
|
+
|
|
1522
|
+
webex.logger.log('a');
|
|
1523
|
+
webex.logger.formatLogs({diff: true});
|
|
1524
|
+
assert.equal(webex.logger.buffer.nextIndex, 1);
|
|
1525
|
+
|
|
1526
|
+
// lastSubmitted defaults to 0 before any call to updateLastSubmittedIndex
|
|
1527
|
+
webex.logger.resetBufferToLastSuccessfulUpload();
|
|
1528
|
+
|
|
1529
|
+
assert.equal(webex.logger.buffer.nextIndex, 0);
|
|
1530
|
+
});
|
|
1531
|
+
});
|
|
1268
1532
|
});
|