From 8c73056693caec6f9e97705e3dbc6205332b50b9 Mon Sep 17 00:00:00 2001 From: Jason Robinson Date: Wed, 21 Aug 2019 16:06:32 +0300 Subject: [PATCH 1/2] Tweak rageshake logging messages Signed-off-by: Jason Robinson --- src/rageshake/rageshake.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/rageshake/rageshake.js b/src/rageshake/rageshake.js index 6366392c04..87c98d105a 100644 --- a/src/rageshake/rageshake.js +++ b/src/rageshake/rageshake.js @@ -74,13 +74,17 @@ class ConsoleLogger { // Convert objects and errors to helpful things args = args.map((arg) => { + let msg = ''; if (arg instanceof Error) { - return arg.message + (arg.stack ? `\n${arg.stack}` : ''); + msg = arg.message + (arg.stack ? `\n${arg.stack}` : ''); } else if (typeof(arg) === 'object') { - return JSON.stringify(arg); + msg = JSON.stringify(arg); } else { - return arg; + msg = arg; } + // Do some cleanup + msg = msg.replace(/token=[a-zA-Z0-9-]+/gm, 'token=xxxxx'); + return msg; }); // Some browsers support string formatting which we're not doing here From f505aa0c8330557256693d9c01166f32347c74b3 Mon Sep 17 00:00:00 2001 From: Jason Robinson Date: Fri, 23 Aug 2019 10:12:46 +0300 Subject: [PATCH 2/2] Ensure logging tweak doesn't fail on undefined Run the replace on the log line string instead of the separate parts since we can ensure the line is a string. Signed-off-by: Jason Robinson --- src/rageshake/rageshake.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/rageshake/rageshake.js b/src/rageshake/rageshake.js index 87c98d105a..1acce0600c 100644 --- a/src/rageshake/rageshake.js +++ b/src/rageshake/rageshake.js @@ -74,17 +74,13 @@ class ConsoleLogger { // Convert objects and errors to helpful things args = args.map((arg) => { - let msg = ''; if (arg instanceof Error) { - msg = arg.message + (arg.stack ? `\n${arg.stack}` : ''); + return arg.message + (arg.stack ? `\n${arg.stack}` : ''); } else if (typeof(arg) === 'object') { - msg = JSON.stringify(arg); + return JSON.stringify(arg); } else { - msg = arg; + return arg; } - // Do some cleanup - msg = msg.replace(/token=[a-zA-Z0-9-]+/gm, 'token=xxxxx'); - return msg; }); // Some browsers support string formatting which we're not doing here @@ -92,7 +88,9 @@ class ConsoleLogger { // run. // Example line: // 2017-01-18T11:23:53.214Z W Failed to set badge count - const line = `${ts} ${level} ${args.join(' ')}\n`; + let line = `${ts} ${level} ${args.join(' ')}\n`; + // Do some cleanup + line = line.replace(/token=[a-zA-Z0-9-]+/gm, 'token=xxxxx'); // Using + really is the quickest way in JS // http://jsperf.com/concat-vs-plus-vs-join this.logs += line;