From a0309c164a394b102ca707203e053c01239b4c0d Mon Sep 17 00:00:00 2001 From: Slincnik Date: Tue, 14 Jan 2025 23:50:48 +0300 Subject: [PATCH] refactor: added debug in many loading func --- src/handlers/command-handler/functions/registerCommands.ts | 2 ++ src/handlers/command-handler/index.ts | 2 +- src/handlers/event-handler/index.ts | 2 ++ src/helpers/logger.ts | 5 +++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/handlers/command-handler/functions/registerCommands.ts b/src/handlers/command-handler/functions/registerCommands.ts index fc88de35..9cfbf1e0 100644 --- a/src/handlers/command-handler/functions/registerCommands.ts +++ b/src/handlers/command-handler/functions/registerCommands.ts @@ -37,6 +37,7 @@ const registerGlobalCommands = async (client: ExtendedClient, commands: CommandF logger.log(`Edited command globally: ${data.name}`); } else if (!targetCommand) { await appCommandsManager.create(data).catch(() => logger.error(`Failed to register command: ${data.name}`)); + logger.debug(`Command ${data.name} loaded globally`); } }), ); @@ -77,6 +78,7 @@ const registerDevCommands = async (client: ExtendedClient, commands: CommandFile logger.log(`Edited command globally: ${data.name}`); } else if (!targetCommand) { await guildCommands.create(data).catch(() => logger.error(`Failed to register command: ${data.name} in ${guildCommands.guild.name} server`)); + logger.debug(`Command ${data.name} loaded in dev`); } }); }), diff --git a/src/handlers/command-handler/index.ts b/src/handlers/command-handler/index.ts index 4775ee52..375f56b6 100644 --- a/src/handlers/command-handler/index.ts +++ b/src/handlers/command-handler/index.ts @@ -94,7 +94,7 @@ export class CommandHandler { interaction, }); } catch (error) { - logger.error(error); + logger.error(error, "Command cannot be executed"); } }); } diff --git a/src/handlers/event-handler/index.ts b/src/handlers/event-handler/index.ts index 88ed23aa..4bedc289 100644 --- a/src/handlers/event-handler/index.ts +++ b/src/handlers/event-handler/index.ts @@ -53,6 +53,8 @@ export class EventHandler { } this.events.push({ data, run }); + + logger.debug(`Event ${eventFilePath} loaded`); } } catch (error) { logger.error("Error build events: ", error); diff --git a/src/helpers/logger.ts b/src/helpers/logger.ts index 27e280f2..65f24e32 100644 --- a/src/helpers/logger.ts +++ b/src/helpers/logger.ts @@ -1,3 +1,4 @@ +import useClient from "@/utils/use-client.js"; import chalk from "chalk"; function format(tDate: Date | number) { @@ -34,6 +35,10 @@ export default { }, debug(...content: unknown[]) { + const client = useClient(); + const isProd = client.configService.get("production"); + console.log(isProd); + if (isProd) return; return console.log(`[${format(Date.now())}]: ${logLevels.DEBUG} ${content.join(" ")}`); },