From 2c0f7f91c17055ded4a2df8084e110ef8bd9bbf3 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Tue, 18 Feb 2025 22:54:43 -0500 Subject: [PATCH] Add new logger for outputting to stdout. --- main.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 958648e..d41d3a5 100644 --- a/main.py +++ b/main.py @@ -9,9 +9,15 @@ from nextcord.ext import commands from utilities import config -logger = logging.getLogger("nextcord") -logger.setLevel(logging.DEBUG) -handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8", mode="w") +nextcord_logger = logging.getLogger("nextcord") +nextcord_logger.setLevel(logging.DEBUG) +nextcord_handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8", mode="w") +nextcord_handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s")) +nextcord_logger.addHandler(nextcord_handler) + +logger = logging.getLogger("default") +logger.setLevel(logging.INFO) +handler = logging.StreamHandler(sys.stdout) handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s")) logger.addHandler(handler) @@ -28,7 +34,7 @@ def main() -> None: intents = nextcord.Intents.default() # Required in order to read messages (eg. prefix commands) - intents.message_content = True # pylint: disable=assigning-non-slot + intents.message_content = True bot = commands.Bot( commands.when_mentioned_or(config.BOT_PREFIX), @@ -42,8 +48,10 @@ def main() -> None: @bot.listen() async def on_ready() -> None: """When Discord is connected.""" - if bot.user is not None: - logger.debug("%s has connected to Discord!", bot.user.name) + if bot.user is None: + logger.error("Discord connection failed.") + return + logger.info("%s has connected to Discord!", bot.user.name) # Run Discord bot bot.run(config.DISCORD_TOKEN)