Move the logger into own module for importing.

This commit is contained in:
2025-03-05 10:50:37 -05:00
parent 0702198f0a
commit 6e25d4e75a
3 changed files with 16 additions and 11 deletions
+2 -2
View File
@@ -11,7 +11,7 @@ from sqlmodel import col
from cogs.submission.verification_view import VerificationView from cogs.submission.verification_view import VerificationView
from database.db import engine from database.db import engine
from database.models import Category, CategoryGroup, Guild, Submission from database.models import Category, CategoryGroup, Guild, Submission
from main import logger from main import agon_logger
from utilities.utils import autofill_categories, autofill_groups, submit_score from utilities.utils import autofill_categories, autofill_groups, submit_score
@@ -108,7 +108,7 @@ class SubmissionCog(commands.Cog):
if not isinstance(channel, nextcord.TextChannel): if not isinstance(channel, nextcord.TextChannel):
await interaction.response.send_message("An error happened with submission.") await interaction.response.send_message("An error happened with submission.")
logger.error( agon_logger.error(
"Channel id %s in guild %s is does not correspond to a TextChannel.", channel.id, channel.guild.id "Channel id %s in guild %s is does not correspond to a TextChannel.", channel.id, channel.guild.id
) )
return return
+4 -9
View File
@@ -8,6 +8,7 @@ import nextcord
from nextcord.ext import commands from nextcord.ext import commands
from utilities import config from utilities import config
from utilities.logger import agon_logger
nextcord_logger = logging.getLogger("nextcord") nextcord_logger = logging.getLogger("nextcord")
nextcord_logger.setLevel(logging.DEBUG) nextcord_logger.setLevel(logging.DEBUG)
@@ -15,18 +16,12 @@ nextcord_handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8"
nextcord_handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s")) nextcord_handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
nextcord_logger.addHandler(nextcord_handler) nextcord_logger.addHandler(nextcord_handler)
logger = logging.getLogger("default")
logger.setLevel(logging.INFO)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
logger.addHandler(handler)
def main() -> None: def main() -> None:
"""Main function for bot.""" """Main function for bot."""
min_python_version = (3, 12) min_python_version = (3, 12)
if sys.version_info < min_python_version: if sys.version_info < min_python_version:
logger.error("ERROR: Python version must be >= 3.12") agon_logger.error("ERROR: Python version must be >= 3.12")
sys.exit() sys.exit()
# Allows privileged intents for monitoring members joining, roles editing, and role assignments # Allows privileged intents for monitoring members joining, roles editing, and role assignments
@@ -46,9 +41,9 @@ def main() -> None:
async def on_ready() -> None: async def on_ready() -> None:
"""When Discord is connected.""" """When Discord is connected."""
if bot.user is None: if bot.user is None:
logger.error("Discord connection failed.") agon_logger.error("Discord connection failed.")
return return
logger.info("%s has connected to Discord!", bot.user.name) agon_logger.info("%s has connected to Discord!", bot.user.name)
# Run Discord bot # Run Discord bot
bot.run(config.DISCORD_TOKEN) bot.run(config.DISCORD_TOKEN)
+10
View File
@@ -0,0 +1,10 @@
"""Creates logger for Agon bot."""
import logging
import sys
agon_logger = logging.getLogger("default")
agon_logger.setLevel(logging.INFO)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
agon_logger.addHandler(handler)