Add dynamic log directory

This commit is contained in:
2025-08-10 06:31:17 -07:00
parent 177febba63
commit 5b393de135
4 changed files with 14 additions and 9 deletions

7
.gitignore vendored
View File

@@ -174,7 +174,8 @@ cython_debug/
# PyPI configuration file
.pypirc
# Other files
# Logs
/logs
# Config file
config.ini
*.log
*.log.*

View File

@@ -1,10 +1,10 @@
{
"401095ca": {
"channel_id": "1392730642206429307",
"message_id": "1396377026000322712"
"message_id": "1404091156421279935"
},
"548c4f18": {
"channel_id": "1392730682576343121",
"message_id": "1396377032589447258"
"message_id": "1404091162607747135"
}
}

View File

@@ -16,6 +16,7 @@ Features:
import discord
from discord.ext import commands, tasks
from discord import app_commands
import os
import aiohttp
import asyncio
import json
@@ -32,14 +33,17 @@ import generate_config
# LOGGING SETUP
# ==============================================
logger = logging.getLogger('pterodactyl_bot')
logs_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logs')
os.makedirs(logs_dir, exist_ok=True)
logger = logging.getLogger('pterodisbot')
logger.setLevel(logging.DEBUG)
# File handler for logs (rotates when reaching 5MB, keeps 3 backups)
handler = RotatingFileHandler(
'pterodactyl_bot.log',
maxBytes=5*1024*1024,
backupCount=3,
filename=os.path.join(logs_dir, 'pterodisbot.log'),
maxBytes=5*1024*1024, # 5 MiB max log file size
backupCount=3, # Rotate through 3 files
encoding='utf-8'
)
handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))