From 20448539922727f047366e105d90e5c05c8c0e2e Mon Sep 17 00:00:00 2001 From: froge Date: Sun, 25 Feb 2024 20:22:45 +1000 Subject: [PATCH] Fix logging --- frogbot.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/frogbot.py b/frogbot.py index f853b8a..288ed19 100644 --- a/frogbot.py +++ b/frogbot.py @@ -7,8 +7,11 @@ from dotenv import load_dotenv # Set discord library logging level to INFO # Configure logging to disk and stderr -logger = logging.getLogger('discord') -logger.setLevel(logging.INFO) +discordpy_logger = logging.getLogger('discord') +discordpy_logger.setLevel(logging.INFO) + +logger = logging.getLogger('frogbot') +logger.setLevel(logging.DEBUG) stderr_loghandler = logging.StreamHandler() loghandler = logging.handlers.RotatingFileHandler( @@ -26,6 +29,8 @@ stderr_loghandler.setFormatter(logger_formatter) logger.addHandler(stderr_loghandler) logger.addHandler(loghandler) +discordpy_logger.addHandler(stderr_loghandler) +discordpy_logger.addHandler(loghandler) # Set up discord intents intents = discord.Intents.default() @@ -37,9 +42,11 @@ client = discord.Client(intents=intents) load_dotenv() bot_token = os.getenv("FROGTOKEN", None) +logger.debug("Bot is starting...") + @client.event async def on_ready(): - logging.info(f'We have logged in as {client.user}') + logger.info(f'We have logged in as {client.user}') @client.event async def on_message(message): @@ -48,6 +55,7 @@ async def on_message(message): if message.content.startswith('$hello'): await message.channel.send('Hello!') + logger.info(f"Sent hello message to {message.author}") # Suppress the default configuration since we have our own client.run(token=bot_token, log_handler=None)