diff --git a/main.py b/main.py index 7429e17..35c6953 100644 --- a/main.py +++ b/main.py @@ -3,11 +3,10 @@ import utils.settings as settings import os from utils.translations import translator -from utils.errorhandling import handle_errors +from utils.errorhandling import handle_errors, setup_logging import utils.constants as constants -import logging -logging.basicConfig(filename=os.path.join('logs', 'bot.log'), level=logging.INFO) +setup_logging() intents = nextcord.Intents.all() bot = commands.Bot( diff --git a/utils/errorhandling.py b/utils/errorhandling.py index 1e5fa05..82aedfd 100644 --- a/utils/errorhandling.py +++ b/utils/errorhandling.py @@ -1,9 +1,29 @@ import nextcord import logging +import os +from logging.handlers import RotatingFileHandler +from datetime import datetime from nextcord.ext import commands from nextcord import Interaction from functools import wraps +def setup_logging(): + if not os.path.exists('logs'): + os.makedirs('logs') + + log_filename = f"palbot_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.log" + log_handler = RotatingFileHandler( + filename=os.path.join('logs', log_filename), + maxBytes=0, + backupCount=5, + encoding='utf-8' + ) + + log_formatter = logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s') + log_handler.setFormatter(log_formatter) + + logging.basicConfig(handlers=[log_handler], level=logging.INFO) + async def handle_errors(interaction, error): try: if interaction.response.is_done():