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 <jasonr@matrix.org>
This commit is contained in:
parent
8c73056693
commit
f505aa0c83
1 changed files with 6 additions and 8 deletions
|
@ -74,17 +74,13 @@ class ConsoleLogger {
|
||||||
|
|
||||||
// Convert objects and errors to helpful things
|
// Convert objects and errors to helpful things
|
||||||
args = args.map((arg) => {
|
args = args.map((arg) => {
|
||||||
let msg = '';
|
|
||||||
if (arg instanceof Error) {
|
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') {
|
} else if (typeof(arg) === 'object') {
|
||||||
msg = JSON.stringify(arg);
|
return JSON.stringify(arg);
|
||||||
} else {
|
} 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
|
// Some browsers support string formatting which we're not doing here
|
||||||
|
@ -92,7 +88,9 @@ class ConsoleLogger {
|
||||||
// run.
|
// run.
|
||||||
// Example line:
|
// Example line:
|
||||||
// 2017-01-18T11:23:53.214Z W Failed to set badge count
|
// 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
|
// Using + really is the quickest way in JS
|
||||||
// http://jsperf.com/concat-vs-plus-vs-join
|
// http://jsperf.com/concat-vs-plus-vs-join
|
||||||
this.logs += line;
|
this.logs += line;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue