FEAT: Added a Logger

REF: Changed Spotify Module to use the logger now
This commit is contained in:
Dan
2024-06-21 13:08:45 -04:00
parent ecea3b93e0
commit 15ed750f8b
4 changed files with 104 additions and 6 deletions

View File

@ -0,0 +1,29 @@
# modules/admin/logger_module.py
import discord
import logging
import logging.config
from .logging_config import logging_config
class LoggerModule:
def __init__(self, bot):
self.bot = bot
logging.config.dictConfig(logging_config)
self.logger = logging.getLogger(__name__)
def add_logging_commands(self):
@self.bot.tree.command(name="log_test",
description="Test the logging system")
async def log_test(interaction: discord.Interaction):
self.logger.debug("This is a debug message")
self.logger.info("This is an info message")
self.logger.warning("This is a warning message")
self.logger.error("This is an error message")
self.logger.critical("This is a critical message")
await interaction.response.send_message("Logging test completed."
"Check the logs!")
async def setup(bot):
logger_module = LoggerModule(bot)
logger_module.add_logging_commands()

View File

@ -0,0 +1,40 @@
# modules/admin/logging_config.py
import logging
import logging.handlers
import os
LOG_DIR = "logs"
if not os.path.exists(LOG_DIR):
os.makedirs(LOG_DIR)
LOG_FILE = os.path.join(LOG_DIR, "selena.log")
logging_config = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"standard": {
"format": "%(asctime)s [%(levelname)s] %(name)s: %(message)s"
},
},
"handlers": {
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "standard",
},
"file_handler": {
"level": "DEBUG",
"class": "logging.handlers.RotatingFileHandler",
"formatter": "standard",
"filename": LOG_FILE,
"maxBytes": 1024*1024*5, # 5 MB
"backupCount": 3,
},
},
"root": {
"handlers": ["console", "file_handler"],
"level": "DEBUG",
},
}