Logging
Ruby logs to two places at once:
bot.login the folder you run the bot from. It's appended to, so the reason for a crash survives the restart. It rotates at 5 MB and keeps three old files (bot.log.1tobot.log.3).- Your log channel (
server.channels.login the config), as embeds coloured by level: 🟦 info and debug, 🟨 warnings, 🟥 errors.
Both use the same log_level from the config (default INFO).
Logging from your code
python
import logging
await self.bot.log(logging.INFO, "Giveaway started")
await self.bot.log(logging.WARNING, f"{member} tried to redeem an expired code")
await self.bot.log(logging.ERROR, f"Couldn't DM {member}: {e}")bot.log() is async because it may send a message to Discord. If you only want the file, or you're somewhere you can't await, use the plain logger:
python
self.bot.logger.debug("Message counted")What Ruby logs by itself
| Level | When |
|---|---|
| INFO | The bot logged in |
| DEBUG | Each cog loaded; each command run, by whom and where |
| WARNING | Someone tried an owner-only command or a command that doesn't exist |
| ERROR | A cog failed to load; a command crashed |
TIP
Set log_level: "DEBUG" while developing to see every cog load and command run. Leave it at INFO in production, or every command posts in your log channel.
INFO
Messages logged before the bot connects (for example while cogs load) only go to bot.log, because the log channel can't be found until the bot is connected.