From 1442055f41f12ccf8483740cd83b7cb74483a656 Mon Sep 17 00:00:00 2001 From: Siwoo Jeon Date: Sun, 23 Feb 2025 18:10:55 +0900 Subject: [PATCH] feat: Add Config.nodeEnv & Set logger level --- src/config.ts | 6 ++++++ src/index.ts | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/config.ts b/src/config.ts index 4ede014..1504e55 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,3 +1,5 @@ +type NodeEnv = 'development' | 'production' + export class Config { private _getRequiredValue(key: string) { const value = process.env[key] @@ -19,4 +21,8 @@ export class Config { public train = { userId: this._getValue('TRAIN_USER_ID'), } + + public nodeEnv: NodeEnv = this._getValue('NODE_ENV') + ? (this._getValue('NODE_ENV') as NodeEnv) + : 'production' } diff --git a/src/index.ts b/src/index.ts index 3bf94ec..b41202e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import './init' -import { SapphireClient } from '@sapphire/framework' +import { LogLevel, SapphireClient } from '@sapphire/framework' import { container } from '@sapphire/pieces' import { GatewayIntentBits, Partials } from 'discord.js' @@ -17,6 +17,15 @@ const client = new SapphireClient({ repliedUser: true, }, partials: [Partials.Message, Partials.ThreadMember], + logger: { + level: + container.config.nodeEnv === 'development' + ? LogLevel.Debug + : LogLevel.Info, + }, }) +client.on('debug', container.logger.debug) +client.on('error', container.logger.error) + client.login(container.config.bot.token)