removed bot.logger, have each cog handle logging

This commit is contained in:
phixxy 2024-02-14 00:00:58 -08:00
parent 95d585b5dd
commit bdcdd87348
13 changed files with 107 additions and 85 deletions

View file

@ -2,22 +2,23 @@ import os
import discord
from discord.ext import commands
from dotenv import load_dotenv
import src.logger as logger
import src.logger
import src.utils as utils
intents = discord.Intents.all()
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
bot.logger = logger.logger_setup()
logger = src.logger.logger_setup()
async def load_cogs(bot: commands.Bot, cog_path: str) -> None:
for plugin_file in os.listdir(cog_path):
if plugin_file[-3:] == '.py':
try:
await bot.load_extension(f'extensions.{plugin_file[:-3]}')
bot.logger.info(f"Successfully loaded plugin {plugin_file}")
logger.info(f"Successfully loaded plugin {plugin_file}")
except:
bot.logger.exception(f"Failed to load plugin {plugin_file}")
logger.exception(f"Failed to load plugin {plugin_file}")
@bot.event
async def on_ready():
@ -25,17 +26,17 @@ async def on_ready():
await utils.delete_all_files("tmp/")
await utils.folder_setup()
await load_cogs(bot, 'extensions/')
bot.logger.info('We have logged in as {0.user}'.format(bot))
logger.info('We have logged in as {0.user}'.format(bot))
except:
bot.logger.warning(f"Error in on_ready")
logger.warning(f"Error in on_ready")
@bot.event
async def on_message(ctx):
try:
await bot.process_commands(ctx)
except commands.CommandNotFound:
bot.logger.info("Command not found.")
logger.info("Command not found.")
except discord.ext.commands.errors.CommandNotFound:
bot.logger.info("Command not found.")
logger.info("Command not found.")
except Exception as e:
bot.logger.warning(f"Error processing commands: {e}")
logger.warning(f"Error processing commands: {e}")