From 9d46abcbb32569c7b7c8de10bb155944548a6860 Mon Sep 17 00:00:00 2001 From: Isaac Date: Mon, 26 Sep 2022 16:39:32 +0100 Subject: [PATCH] Improve logging --- .eslintrc.json | 2 +- src/lib/logger.js | 2 +- src/listeners/autocomplete/componentLoad.js | 2 +- src/listeners/autocomplete/run.js | 19 +++++++++++++++++++ src/listeners/buttons/componentLoad.js | 2 +- src/listeners/buttons/run.js | 19 +++++++++++++++++++ src/listeners/menus/componentLoad.js | 2 +- src/listeners/menus/run.js | 19 +++++++++++++++++++ src/listeners/modals/componentLoad.js | 2 +- src/listeners/modals/run.js | 19 +++++++++++++++++++ src/listeners/stdin/unknown.js | 2 +- 11 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 src/listeners/autocomplete/run.js create mode 100644 src/listeners/buttons/run.js create mode 100644 src/listeners/menus/run.js create mode 100644 src/listeners/modals/run.js diff --git a/.eslintrc.json b/.eslintrc.json index dc66be5..0e95594 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -127,7 +127,7 @@ "off" ], "no-console": [ - "off" + "warn" ], "no-prototype-builtins": [ "off" diff --git a/src/lib/logger.js b/src/lib/logger.js index e30e15e..a0af18a 100644 --- a/src/lib/logger.js +++ b/src/lib/logger.js @@ -38,7 +38,7 @@ module.exports = config => { } return new Logger({ - namespaces: ['commands', 'http', 'listeners', 'settings', 'tickets'], + namespaces: ['autocomplete', 'buttons', 'commands', 'http', 'listeners', 'menus', 'modals', 'settings', 'tickets'], transports, }); }; diff --git a/src/listeners/autocomplete/componentLoad.js b/src/listeners/autocomplete/componentLoad.js index 26e81b0..04a1743 100644 --- a/src/listeners/autocomplete/componentLoad.js +++ b/src/listeners/autocomplete/componentLoad.js @@ -10,7 +10,7 @@ module.exports = class extends Listener { } run(autocompleter) { - this.client.log.info(`Loaded "${autocompleter.id}" autocompleter`); + this.client.log.info.autocomplete(`Loaded "${autocompleter.id}" autocompleter`); return true; } }; diff --git a/src/listeners/autocomplete/run.js b/src/listeners/autocomplete/run.js new file mode 100644 index 0000000..e691629 --- /dev/null +++ b/src/listeners/autocomplete/run.js @@ -0,0 +1,19 @@ +const { Listener } = require('@eartharoid/dbf'); + +module.exports = class extends Listener { + constructor(client, options) { + super(client, { + ...options, + emitter: client.autocomplete, + event: 'run', + }); + } + + run({ + autocompleter, + interaction, + }) { + this.client.log.verbose.autocomplete(`${interaction.user.tag} used the "${autocompleter.id}" autocompleter`); + return true; + } +}; diff --git a/src/listeners/buttons/componentLoad.js b/src/listeners/buttons/componentLoad.js index 246948d..2bcc5c2 100644 --- a/src/listeners/buttons/componentLoad.js +++ b/src/listeners/buttons/componentLoad.js @@ -10,7 +10,7 @@ module.exports = class extends Listener { } run(button) { - this.client.log.info(`Loaded "${button.id}" button`); + this.client.log.info.buttons(`Loaded "${button.id}" button`); return true; } }; diff --git a/src/listeners/buttons/run.js b/src/listeners/buttons/run.js new file mode 100644 index 0000000..d33167e --- /dev/null +++ b/src/listeners/buttons/run.js @@ -0,0 +1,19 @@ +const { Listener } = require('@eartharoid/dbf'); + +module.exports = class extends Listener { + constructor(client, options) { + super(client, { + ...options, + emitter: client.buttons, + event: 'run', + }); + } + + run({ + button, + interaction, + }) { + this.client.log.info.buttons(`${interaction.user.tag} used the "${button.id}" button`); + return true; + } +}; diff --git a/src/listeners/menus/componentLoad.js b/src/listeners/menus/componentLoad.js index 03290de..4e1c3d3 100644 --- a/src/listeners/menus/componentLoad.js +++ b/src/listeners/menus/componentLoad.js @@ -10,7 +10,7 @@ module.exports = class extends Listener { } run(menu) { - this.client.log.info(`Loaded "${menu.id}" menu`); + this.client.log.info.menus(`Loaded "${menu.id}" menu`); return true; } }; diff --git a/src/listeners/menus/run.js b/src/listeners/menus/run.js new file mode 100644 index 0000000..ab1fba2 --- /dev/null +++ b/src/listeners/menus/run.js @@ -0,0 +1,19 @@ +const { Listener } = require('@eartharoid/dbf'); + +module.exports = class extends Listener { + constructor(client, options) { + super(client, { + ...options, + emitter: client.menus, + event: 'run', + }); + } + + run({ + menu, + interaction, + }) { + this.client.log.info.menus(`${interaction.user.tag} used the "${menu.id}" menu`); + return true; + } +}; diff --git a/src/listeners/modals/componentLoad.js b/src/listeners/modals/componentLoad.js index a9454e2..cccd669 100644 --- a/src/listeners/modals/componentLoad.js +++ b/src/listeners/modals/componentLoad.js @@ -10,7 +10,7 @@ module.exports = class extends Listener { } run(modal) { - this.client.log.info(`Loaded "${modal.id}" modal`); + this.client.log.info.modals(`Loaded "${modal.id}" modal`); return true; } }; diff --git a/src/listeners/modals/run.js b/src/listeners/modals/run.js new file mode 100644 index 0000000..87003e0 --- /dev/null +++ b/src/listeners/modals/run.js @@ -0,0 +1,19 @@ +const { Listener } = require('@eartharoid/dbf'); + +module.exports = class extends Listener { + constructor(client, options) { + super(client, { + ...options, + emitter: client.modals, + event: 'run', + }); + } + + run({ + modal, + interaction, + }) { + this.client.log.info.modals(`${interaction.user.tag} used the "${modal.id}" modal`); + return true; + } +}; diff --git a/src/listeners/stdin/unknown.js b/src/listeners/stdin/unknown.js index d68e27a..976ce95 100644 --- a/src/listeners/stdin/unknown.js +++ b/src/listeners/stdin/unknown.js @@ -10,6 +10,6 @@ module.exports = class extends Listener { } run(commandName) { - console.log('Unknown command:', commandName); + this.client.log.warn('Unknown command:', commandName); } };