From 54dff4399d424a929e1ae83ee59dd69c1ae0ba92 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Thu, 14 Jul 2022 01:24:46 +0300 Subject: [PATCH] tweaks to logger webhook --- src/middleware/Logger.js | 17 ++++++++++++----- src/structure/client/LocaleLoader.js | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/middleware/Logger.js b/src/middleware/Logger.js index bb8354f..73e756a 100644 --- a/src/middleware/Logger.js +++ b/src/middleware/Logger.js @@ -23,6 +23,13 @@ const Constants = { info: 'blue', debug: 'magenta', status: 'cyanBright' + }, + ColorCodes: { + error: 0xe88388, + warn: 0xf9d472, + info: 0x76a9d8, + debug: 0xd8abd7, + status: 0x72d4d7 } }; @@ -52,7 +59,7 @@ class Logger { } - write(type = 'info', string = '', shard = null, api = false) { + write(type = 'info', string = '', shard = null, api = false, broadcast = false) { type = type.toLowerCase(); @@ -67,7 +74,7 @@ class Logger { const strippedText = text.replace(stripRegex, ''); console.log(text); //eslint-disable-line no-console - if (type === 'error') this.webhook(strippedText); + if (type === 'error' || broadcast) this.webhook(strippedText, type); const stream = type === 'error' ? '_errorWriteStream' : '_writeStream'; if(this[stream]) { @@ -77,13 +84,13 @@ class Logger { } - webhook(text) { + webhook(text, type) { const message = text.replace(new RegExp(process.env.DISCORD_TOKEN, 'gu'), '') .replace(new RegExp(username, 'gu'), ''); const embed = { - color: 0xe88388, + color: Constants.ColorCodes[type], timestamp: new Date(), description: `\`\`\`${message.length > 2000 ? message.substring(0, 2000) + ' ... CONTENT CUT OFF' : message}\`\`\``, }; @@ -123,7 +130,7 @@ class Logger { //Messages coming from the shards process.send functions. _handleMessage(shard, message) { - this.write(message.type, message.message, shard, message._api); + this.write(message.type, message.message, shard, message._api, message.broadcast); } _shardId(shard) { diff --git a/src/structure/client/LocaleLoader.js b/src/structure/client/LocaleLoader.js index 8ea556c..29987ee 100644 --- a/src/structure/client/LocaleLoader.js +++ b/src/structure/client/LocaleLoader.js @@ -33,7 +33,7 @@ class LocaleLoader { let string = this.languages[language][index]; if (!string) { const str = `< Missing Locale Index: ${language}.${index} >`; - this.logger.error(str); + this.logger.warn(str, { broadcast: true }); return str; }