Fix logging
This commit is contained in:
parent
46799bb327
commit
2044853992
1 changed files with 11 additions and 3 deletions
14
frogbot.py
14
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)
|
||||
|
|
Loading…
Add table
Reference in a new issue