Skip to content

Commit

Permalink
Improved Logging System
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoz committed Sep 30, 2024
1 parent 68f808b commit 988faa2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 2 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
20 changes: 20 additions & 0 deletions utils/errorhandling.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down

0 comments on commit 988faa2

Please sign in to comment.