@webex/plugin-logger 3.0.0-beta.13 → 3.0.0-beta.15
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.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/logger.js +1 -1
- 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 +53 -43
- package/test/unit/spec/logger.js +235 -96
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["logger","level","process","env","WEBEX_LOG_LEVEL","historyLength"],"sources":["config.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n/**\n * @typedef {Object} LoggerConfig\n * @property {string} [level=process.env.WEBEX_LOG_LEVEL] - Maximum log level that\n * should be printed to the console. One of\n * silent|error|warn|log|info|debug|trace\n * @property {number} [historyLength=1000] - Maximum number of entries to store in the log buffer.\n * @example\n * {\n * level: process.env.WEBEX_LOG_LEVEL,\n * historyLength: 1000\n * }\n */\n\nexport default {\n logger: {\n level: process.env.WEBEX_LOG_LEVEL,\n historyLength: 1000
|
|
1
|
+
{"version":3,"names":["logger","level","process","env","WEBEX_LOG_LEVEL","historyLength"],"sources":["config.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n/**\n * @typedef {Object} LoggerConfig\n * @property {string} [level=process.env.WEBEX_LOG_LEVEL] - Maximum log level that\n * should be printed to the console. One of\n * silent|error|warn|log|info|debug|trace\n * @property {number} [historyLength=1000] - Maximum number of entries to store in the log buffer.\n * @example\n * {\n * level: process.env.WEBEX_LOG_LEVEL,\n * historyLength: 1000\n * }\n */\n\nexport default {\n logger: {\n level: process.env.WEBEX_LOG_LEVEL,\n historyLength: 1000,\n },\n};\n"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;eAEe;EACbA,MAAM,EAAE;IACNC,KAAK,EAAEC,OAAO,CAACC,GAAR,CAAYC,eADb;IAENC,aAAa,EAAE;EAFT;AADK,C"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["registerPlugin","Logger","config","replace"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {registerPlugin} from '@webex/webex-core';\n\nimport Logger from './logger';\nimport config from './config';\n\nregisterPlugin('logger', Logger, {\n config,\n replace: true
|
|
1
|
+
{"version":3,"names":["registerPlugin","Logger","config","replace"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {registerPlugin} from '@webex/webex-core';\n\nimport Logger from './logger';\nimport config from './config';\n\nregisterPlugin('logger', Logger, {\n config,\n replace: true,\n});\n\nexport {default, levels} from './logger';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA;;AAEA;;AACA;;;;;;AAPA;AACA;AACA;AAOA,IAAAA,yBAAA,EAAe,QAAf,EAAyBC,eAAzB,EAAiC;EAC/BC,MAAM,EAANA,eAD+B;EAE/BC,OAAO,EAAE;AAFsB,CAAjC"}
|
package/dist/logger.js
CHANGED
package/dist/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["precedence","silent","group","groupEnd","error","warn","log","info","debug","trace","levels","filter","level","fallbacks","LOG_TYPES","SDK","CLIENT","SDK_LOG_TYPE_NAME","authTokenKeyPattern","walkAndFilter","object","visited","includes","push","map","o","patterns","containsEmails","test","replace","key","value","Logger","WebexPlugin","extend","namespace","derived","cache","fn","getCurrentLevel","client_level","getCurrentClientLevel","session","buffer","type","default","groupLevel","sdkBuffer","clientBuffer","args","arg","Error","process","env","NODE_ENV","inBrowser","ret","toString","stack","shouldPrint","shouldBuffer","config","bufferLogLevel","WEBEX_LOG_LEVEL","webex","internal","device","features","developer","get","clientLevel","formatLogs","getDate","clientIndex","sdkIndex","separateLogBuffers","length","Date","join","makeLoggerMethod","impl","neverPrint","alwaysBuffer","wrappedConsoleMethod","logType","clientName","historyLength","clientHistoryLength","filtered","stringified","item","WebexHttpError","toPrint","unshift","url","slice","console","logDate","toISOString","repeat","shift","reason","forEach","impls","pop","prototype","client_logToBuffer","logToBuffer"],"sources":["logger.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {inBrowser, patterns} from '@webex/common';\nimport {\n WebexHttpError,\n WebexPlugin\n} from '@webex/webex-core';\nimport {\n cloneDeep,\n has,\n isArray,\n isObject,\n isString\n} 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 }\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 }\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: 'array',\n default() {\n return [];\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: 'array',\n default() {\n return [];\n }\n },\n clientBuffer: {\n type: 'array',\n default() {\n return [];\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 precedence[level] <= precedence[type === LOG_TYPES.SDK ? this.getCurrentLevel() : this.getCurrentClientLevel()];\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 precedence[level] <= (this.config.bufferLogLevel ? precedence[this.config.bufferLogLevel] : precedence.info);\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 = 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 * @returns {string} formatted buffer\n */\n formatLogs() {\n function getDate(log) {\n return log[1];\n }\n let buffer = [];\n let clientIndex = 0;\n let sdkIndex = 0;\n\n if (this.config.separateLogBuffers) {\n // merge the client and sdk buffers\n // while we have entries in either buffer\n while (clientIndex < this.clientBuffer.length || sdkIndex < this.sdkBuffer.length) {\n // if we have remaining entries in the SDK buffer\n if (sdkIndex < this.sdkBuffer.length &&\n // and we haven't exhausted all the client buffer entries, or SDK date is before client date\n (clientIndex >= this.clientBuffer.length ||\n (new Date(getDate(this.sdkBuffer[sdkIndex])) <= new Date(getDate(this.clientBuffer[clientIndex]))))) {\n // then add to the SDK buffer\n buffer.push(this.sdkBuffer[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.length) {\n buffer.push(this.clientBuffer[clientIndex]);\n clientIndex += 1;\n }\n }\n }\n else {\n buffer = this.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 = logType === LOG_TYPES.SDK ? SDK_LOG_TYPE_NAME : (this.config.clientName || logType);\n\n let buffer;\n let historyLength;\n\n if (this.config.separateLogBuffers) {\n historyLength = this.config.clientHistoryLength ? this.config.clientHistoryLength : this.config.historyLength;\n buffer = logType === LOG_TYPES.SDK ? this.sdkBuffer : this.clientBuffer;\n }\n else {\n buffer = 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 WebexHttpError) {\n return item.toString();\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 buffer.push(stringified);\n if (buffer.length > historyLength) {\n buffer.shift();\n }\n if (level === 'group') this.groupLevel += 1;\n if (level === 'groupEnd' && this.groupLevel > 0) this.groupLevel -= 1;\n }\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\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 =\n makeLoggerMethod(levels.info, levels.info, LOG_TYPES.CLIENT, true, true);\nLogger.prototype.logToBuffer = makeLoggerMethod(levels.info, levels.info, LOG_TYPES.SDK, true, true);\n\nexport default Logger;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA;;AACA;;AALA;AACA;AACA;AAeA,IAAMA,UAAU,GAAG;EACjBC,MAAM,EAAE,CADS;EAEjBC,KAAK,EAAE,CAFU;EAGjBC,QAAQ,EAAE,CAHO;EAIjBC,KAAK,EAAE,CAJU;EAKjBC,IAAI,EAAE,CALW;EAMjBC,GAAG,EAAE,CANY;EAO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AN,EAAP;IACD;EACF,CAVuB,CAaxB;;;EACAxE,MAAM,CAACyE,SAAP,kBAA2B7F,KAA3B,KAAsCmE,gBAAgB,CAACnE,KAAD,EAAQoE,IAAR,EAAclE,SAAS,CAACE,MAAxB,CAAtD;EACAgB,MAAM,CAACyE,SAAP,CAAiB7F,KAAjB,IAA0BmE,gBAAgB,CAACnE,KAAD,EAAQoE,IAAR,EAAclE,SAAS,CAACC,GAAxB,CAA1C;AACD,CAhBD;AAkBAiB,MAAM,CAACyE,SAAP,CAAiBC,kBAAjB,GACE3B,gBAAgB,CAACrE,MAAM,CAACH,IAAR,EAAcG,MAAM,CAACH,IAArB,EAA2BO,SAAS,CAACE,MAArC,EAA6C,IAA7C,EAAmD,IAAnD,CADlB;AAEAgB,MAAM,CAACyE,SAAP,CAAiBE,WAAjB,GAA+B5B,gBAAgB,CAACrE,MAAM,CAACH,IAAR,EAAcG,MAAM,CAACH,IAArB,EAA2BO,SAAS,CAACC,GAArC,EAA0C,IAA1C,EAAgD,IAAhD,CAA/C;gBAEeiB,M"}
|
|
1
|
+
{"version":3,"names":["precedence","silent","group","groupEnd","error","warn","log","info","debug","trace","levels","filter","level","fallbacks","LOG_TYPES","SDK","CLIENT","SDK_LOG_TYPE_NAME","authTokenKeyPattern","walkAndFilter","object","visited","includes","push","map","o","patterns","containsEmails","test","replace","key","value","Logger","WebexPlugin","extend","namespace","derived","cache","fn","getCurrentLevel","client_level","getCurrentClientLevel","session","buffer","type","default","groupLevel","sdkBuffer","clientBuffer","args","arg","Error","process","env","NODE_ENV","inBrowser","ret","toString","stack","shouldPrint","shouldBuffer","config","bufferLogLevel","WEBEX_LOG_LEVEL","webex","internal","device","features","developer","get","clientLevel","formatLogs","getDate","clientIndex","sdkIndex","separateLogBuffers","length","Date","join","makeLoggerMethod","impl","neverPrint","alwaysBuffer","wrappedConsoleMethod","logType","clientName","historyLength","clientHistoryLength","filtered","stringified","item","WebexHttpError","toPrint","unshift","url","slice","console","logDate","toISOString","repeat","shift","reason","forEach","impls","pop","prototype","client_logToBuffer","logToBuffer"],"sources":["logger.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {inBrowser, patterns} from '@webex/common';\nimport {WebexHttpError, 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 }\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: 'array',\n default() {\n return [];\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: 'array',\n default() {\n return [];\n },\n },\n clientBuffer: {\n type: 'array',\n default() {\n return [];\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 * @returns {string} formatted buffer\n */\n formatLogs() {\n function getDate(log) {\n return log[1];\n }\n let buffer = [];\n let clientIndex = 0;\n let sdkIndex = 0;\n\n if (this.config.separateLogBuffers) {\n // merge the client and sdk buffers\n // while we have entries in either buffer\n while (clientIndex < this.clientBuffer.length || sdkIndex < this.sdkBuffer.length) {\n // if we have remaining entries in the SDK buffer\n if (\n sdkIndex < this.sdkBuffer.length &&\n // and we haven't exhausted all the client buffer entries, or SDK date is before client date\n (clientIndex >= this.clientBuffer.length ||\n new Date(getDate(this.sdkBuffer[sdkIndex])) <=\n new Date(getDate(this.clientBuffer[clientIndex])))\n ) {\n // then add to the SDK buffer\n buffer.push(this.sdkBuffer[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.length) {\n buffer.push(this.clientBuffer[clientIndex]);\n clientIndex += 1;\n }\n }\n } else {\n buffer = this.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 buffer;\n let historyLength;\n\n if (this.config.separateLogBuffers) {\n historyLength = this.config.clientHistoryLength\n ? this.config.clientHistoryLength\n : this.config.historyLength;\n buffer = logType === LOG_TYPES.SDK ? this.sdkBuffer : this.clientBuffer;\n } else {\n buffer = 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 WebexHttpError) {\n return item.toString();\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 buffer.push(stringified);\n if (buffer.length > historyLength) {\n buffer.shift();\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;;AACA;;AALA;AACA;AACA;AAMA,IAAMA,UAAU,GAAG;EACjBC,MAAM,EAAE,CADS;EAEjBC,KAAK,EAAE,CAFU;EAGjBC,QAAQ,EAAE,CAHO;EAIjBC,KAAK,EAAE,CAJU;EAKjBC,IAAI,EAAE,CALW;EAMjBC,GAAG,EAAE,CANY;EAOjBC,IAAI,EAAE,CAPW;EAQjBC,KAAK,EAAE,CARU;EASjBC,KAAK,EAAE;AATU,CAAnB;AAYO,IAAMC,MAAM,GAAG,mBAAYV,UAAZ,EAAwBW,MAAxB,CAA+B,UAACC,KAAD;EAAA,OAAWA,KAAK,KAAK,QAArB;AAAA,CAA/B,CAAf;;AAEP,IAAMC,SAAS,GA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AclE,SAAS,CAACC,GAAxB,CAA1C;AACD,CAfD;AAiBAiB,MAAM,CAACyE,SAAP,CAAiBC,kBAAjB,GAAsC3B,gBAAgB,CACpDrE,MAAM,CAACH,IAD6C,EAEpDG,MAAM,CAACH,IAF6C,EAGpDO,SAAS,CAACE,MAH0C,EAIpD,IAJoD,EAKpD,IALoD,CAAtD;AAOAgB,MAAM,CAACyE,SAAP,CAAiBE,WAAjB,GAA+B5B,gBAAgB,CAC7CrE,MAAM,CAACH,IADsC,EAE7CG,MAAM,CAACH,IAFsC,EAG7CO,SAAS,CAACC,GAHmC,EAI7C,IAJ6C,EAK7C,IAL6C,CAA/C;gBAQeiB,M"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webex/plugin-logger",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.15",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
"sinon": "^9.2.4"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@webex/common": "3.0.0-beta.
|
|
27
|
-
"@webex/plugin-logger": "3.0.0-beta.
|
|
28
|
-
"@webex/test-helper-chai": "3.0.0-beta.
|
|
29
|
-
"@webex/test-helper-mocha": "3.0.0-beta.
|
|
30
|
-
"@webex/test-helper-mock-webex": "3.0.0-beta.
|
|
31
|
-
"@webex/webex-core": "3.0.0-beta.
|
|
26
|
+
"@webex/common": "3.0.0-beta.15",
|
|
27
|
+
"@webex/plugin-logger": "3.0.0-beta.15",
|
|
28
|
+
"@webex/test-helper-chai": "3.0.0-beta.15",
|
|
29
|
+
"@webex/test-helper-mocha": "3.0.0-beta.15",
|
|
30
|
+
"@webex/test-helper-mock-webex": "3.0.0-beta.15",
|
|
31
|
+
"@webex/webex-core": "3.0.0-beta.15",
|
|
32
32
|
"lodash": "^4.17.21"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/config.js
CHANGED
package/src/index.js
CHANGED
package/src/logger.js
CHANGED
|
@@ -3,17 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import {inBrowser, patterns} from '@webex/common';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
WebexPlugin
|
|
9
|
-
} from '@webex/webex-core';
|
|
10
|
-
import {
|
|
11
|
-
cloneDeep,
|
|
12
|
-
has,
|
|
13
|
-
isArray,
|
|
14
|
-
isObject,
|
|
15
|
-
isString
|
|
16
|
-
} from 'lodash';
|
|
6
|
+
import {WebexHttpError, WebexPlugin} from '@webex/webex-core';
|
|
7
|
+
import {cloneDeep, has, isArray, isObject, isString} from 'lodash';
|
|
17
8
|
|
|
18
9
|
const precedence = {
|
|
19
10
|
silent: 0,
|
|
@@ -24,7 +15,7 @@ const precedence = {
|
|
|
24
15
|
log: 5,
|
|
25
16
|
info: 6,
|
|
26
17
|
debug: 7,
|
|
27
|
-
trace: 8
|
|
18
|
+
trace: 8,
|
|
28
19
|
};
|
|
29
20
|
|
|
30
21
|
export const levels = Object.keys(precedence).filter((level) => level !== 'silent');
|
|
@@ -34,12 +25,12 @@ const fallbacks = {
|
|
|
34
25
|
warn: ['error', 'log'],
|
|
35
26
|
info: ['log'],
|
|
36
27
|
debug: ['info', 'log'],
|
|
37
|
-
trace: ['debug', 'info', 'log']
|
|
28
|
+
trace: ['debug', 'info', 'log'],
|
|
38
29
|
};
|
|
39
30
|
|
|
40
31
|
const LOG_TYPES = {
|
|
41
32
|
SDK: 'sdk',
|
|
42
|
-
CLIENT: 'client'
|
|
33
|
+
CLIENT: 'client',
|
|
43
34
|
};
|
|
44
35
|
|
|
45
36
|
const SDK_LOG_TYPE_NAME = 'wx-js-sdk';
|
|
@@ -77,8 +68,7 @@ function walkAndFilter(object, visited = []) {
|
|
|
77
68
|
for (const [key, value] of Object.entries(object)) {
|
|
78
69
|
if (authTokenKeyPattern.test(key)) {
|
|
79
70
|
Reflect.deleteProperty(object, key);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
71
|
+
} else {
|
|
82
72
|
object[key] = walkAndFilter(value, visited);
|
|
83
73
|
}
|
|
84
74
|
}
|
|
@@ -97,14 +87,14 @@ const Logger = WebexPlugin.extend({
|
|
|
97
87
|
cache: false,
|
|
98
88
|
fn() {
|
|
99
89
|
return this.getCurrentLevel();
|
|
100
|
-
}
|
|
90
|
+
},
|
|
101
91
|
},
|
|
102
92
|
client_level: {
|
|
103
93
|
cache: false,
|
|
104
94
|
fn() {
|
|
105
95
|
return this.getCurrentClientLevel();
|
|
106
|
-
}
|
|
107
|
-
}
|
|
96
|
+
},
|
|
97
|
+
},
|
|
108
98
|
},
|
|
109
99
|
session: {
|
|
110
100
|
// for when configured to use single buffer
|
|
@@ -112,27 +102,27 @@ const Logger = WebexPlugin.extend({
|
|
|
112
102
|
type: 'array',
|
|
113
103
|
default() {
|
|
114
104
|
return [];
|
|
115
|
-
}
|
|
105
|
+
},
|
|
116
106
|
},
|
|
117
107
|
groupLevel: {
|
|
118
108
|
type: 'number',
|
|
119
109
|
default() {
|
|
120
110
|
return 0;
|
|
121
|
-
}
|
|
111
|
+
},
|
|
122
112
|
},
|
|
123
113
|
// for when configured to use separate buffers
|
|
124
114
|
sdkBuffer: {
|
|
125
115
|
type: 'array',
|
|
126
116
|
default() {
|
|
127
117
|
return [];
|
|
128
|
-
}
|
|
118
|
+
},
|
|
129
119
|
},
|
|
130
120
|
clientBuffer: {
|
|
131
121
|
type: 'array',
|
|
132
122
|
default() {
|
|
133
123
|
return [];
|
|
134
|
-
}
|
|
135
|
-
}
|
|
124
|
+
},
|
|
125
|
+
},
|
|
136
126
|
},
|
|
137
127
|
|
|
138
128
|
/**
|
|
@@ -178,7 +168,10 @@ const Logger = WebexPlugin.extend({
|
|
|
178
168
|
* @returns {boolean}
|
|
179
169
|
*/
|
|
180
170
|
shouldPrint(level, type = LOG_TYPES.SDK) {
|
|
181
|
-
return
|
|
171
|
+
return (
|
|
172
|
+
precedence[level] <=
|
|
173
|
+
precedence[type === LOG_TYPES.SDK ? this.getCurrentLevel() : this.getCurrentClientLevel()]
|
|
174
|
+
);
|
|
182
175
|
},
|
|
183
176
|
|
|
184
177
|
/**
|
|
@@ -194,7 +187,10 @@ const Logger = WebexPlugin.extend({
|
|
|
194
187
|
* @returns {boolean}
|
|
195
188
|
*/
|
|
196
189
|
shouldBuffer(level) {
|
|
197
|
-
return
|
|
190
|
+
return (
|
|
191
|
+
precedence[level] <=
|
|
192
|
+
(this.config.bufferLogLevel ? precedence[this.config.bufferLogLevel] : precedence.info)
|
|
193
|
+
);
|
|
198
194
|
},
|
|
199
195
|
|
|
200
196
|
/**
|
|
@@ -223,7 +219,8 @@ const Logger = WebexPlugin.extend({
|
|
|
223
219
|
}
|
|
224
220
|
|
|
225
221
|
// Use server-side-feature toggles to configure log levels
|
|
226
|
-
const level =
|
|
222
|
+
const level =
|
|
223
|
+
this.webex.internal.device && this.webex.internal.device.features.developer.get('log-level');
|
|
227
224
|
|
|
228
225
|
if (level) {
|
|
229
226
|
if (levels.includes(level)) {
|
|
@@ -275,11 +272,14 @@ const Logger = WebexPlugin.extend({
|
|
|
275
272
|
// merge the client and sdk buffers
|
|
276
273
|
// while we have entries in either buffer
|
|
277
274
|
while (clientIndex < this.clientBuffer.length || sdkIndex < this.sdkBuffer.length) {
|
|
278
|
-
|
|
279
|
-
if (
|
|
275
|
+
// if we have remaining entries in the SDK buffer
|
|
276
|
+
if (
|
|
277
|
+
sdkIndex < this.sdkBuffer.length &&
|
|
280
278
|
// and we haven't exhausted all the client buffer entries, or SDK date is before client date
|
|
281
279
|
(clientIndex >= this.clientBuffer.length ||
|
|
282
|
-
|
|
280
|
+
new Date(getDate(this.sdkBuffer[sdkIndex])) <=
|
|
281
|
+
new Date(getDate(this.clientBuffer[clientIndex])))
|
|
282
|
+
) {
|
|
283
283
|
// then add to the SDK buffer
|
|
284
284
|
buffer.push(this.sdkBuffer[sdkIndex]);
|
|
285
285
|
sdkIndex += 1;
|
|
@@ -291,13 +291,12 @@ const Logger = WebexPlugin.extend({
|
|
|
291
291
|
clientIndex += 1;
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
294
|
+
} else {
|
|
296
295
|
buffer = this.buffer;
|
|
297
296
|
}
|
|
298
297
|
|
|
299
298
|
return buffer.join('\n');
|
|
300
|
-
}
|
|
299
|
+
},
|
|
301
300
|
});
|
|
302
301
|
|
|
303
302
|
/**
|
|
@@ -323,16 +322,18 @@ function makeLoggerMethod(level, impl, type, neverPrint = false, alwaysBuffer =
|
|
|
323
322
|
// in Ampersand, even if the initialize method is used to set this up. so we keep the type to achieve
|
|
324
323
|
// a sort of late binding to allow retrieving a name from config.
|
|
325
324
|
const logType = type;
|
|
326
|
-
const clientName =
|
|
325
|
+
const clientName =
|
|
326
|
+
logType === LOG_TYPES.SDK ? SDK_LOG_TYPE_NAME : this.config.clientName || logType;
|
|
327
327
|
|
|
328
328
|
let buffer;
|
|
329
329
|
let historyLength;
|
|
330
330
|
|
|
331
331
|
if (this.config.separateLogBuffers) {
|
|
332
|
-
historyLength = this.config.clientHistoryLength
|
|
332
|
+
historyLength = this.config.clientHistoryLength
|
|
333
|
+
? this.config.clientHistoryLength
|
|
334
|
+
: this.config.historyLength;
|
|
333
335
|
buffer = logType === LOG_TYPES.SDK ? this.sdkBuffer : this.clientBuffer;
|
|
334
|
-
}
|
|
335
|
-
else {
|
|
336
|
+
} else {
|
|
336
337
|
buffer = this.buffer;
|
|
337
338
|
historyLength = this.config.historyLength;
|
|
338
339
|
}
|
|
@@ -381,8 +382,7 @@ function makeLoggerMethod(level, impl, type, neverPrint = false, alwaysBuffer =
|
|
|
381
382
|
if (level === 'group') this.groupLevel += 1;
|
|
382
383
|
if (level === 'groupEnd' && this.groupLevel > 0) this.groupLevel -= 1;
|
|
383
384
|
}
|
|
384
|
-
}
|
|
385
|
-
catch (reason) {
|
|
385
|
+
} catch (reason) {
|
|
386
386
|
if (!neverPrint) {
|
|
387
387
|
/* istanbul ignore next */
|
|
388
388
|
// eslint-disable-next-line no-console
|
|
@@ -404,14 +404,24 @@ levels.forEach((level) => {
|
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
406
|
|
|
407
|
-
|
|
408
407
|
// eslint-disable-next-line complexity
|
|
409
408
|
Logger.prototype[`client_${level}`] = makeLoggerMethod(level, impl, LOG_TYPES.CLIENT);
|
|
410
409
|
Logger.prototype[level] = makeLoggerMethod(level, impl, LOG_TYPES.SDK);
|
|
411
410
|
});
|
|
412
411
|
|
|
413
|
-
Logger.prototype.client_logToBuffer =
|
|
414
|
-
|
|
415
|
-
|
|
412
|
+
Logger.prototype.client_logToBuffer = makeLoggerMethod(
|
|
413
|
+
levels.info,
|
|
414
|
+
levels.info,
|
|
415
|
+
LOG_TYPES.CLIENT,
|
|
416
|
+
true,
|
|
417
|
+
true
|
|
418
|
+
);
|
|
419
|
+
Logger.prototype.logToBuffer = makeLoggerMethod(
|
|
420
|
+
levels.info,
|
|
421
|
+
levels.info,
|
|
422
|
+
LOG_TYPES.SDK,
|
|
423
|
+
true,
|
|
424
|
+
true
|
|
425
|
+
);
|
|
416
426
|
|
|
417
427
|
export default Logger;
|
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);
|