mirror of https://github.com/stijndcl/didier
Send logs in an embed
parent
d9272f17ab
commit
f19a832725
|
@ -0,0 +1,21 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import discord
|
||||||
|
|
||||||
|
__all__ = ["create_logging_embed"]
|
||||||
|
|
||||||
|
|
||||||
|
def create_logging_embed(level: int, message: str) -> discord.Embed:
|
||||||
|
"""Create an embed to send to the logging channel"""
|
||||||
|
colours = {
|
||||||
|
logging.DEBUG: discord.Colour.light_gray(),
|
||||||
|
logging.ERROR: discord.Colour.red(),
|
||||||
|
logging.INFO: discord.Colour.blue(),
|
||||||
|
logging.WARNING: discord.Colour.yellow(),
|
||||||
|
}
|
||||||
|
|
||||||
|
colour = colours.get(level, discord.Colour.red())
|
||||||
|
embed = discord.Embed(colour=colour, title="Logging")
|
||||||
|
embed.description = message
|
||||||
|
|
||||||
|
return embed
|
|
@ -16,6 +16,7 @@ from database.crud import command_stats, custom_commands
|
||||||
from database.engine import DBSession
|
from database.engine import DBSession
|
||||||
from database.utils.caches import CacheManager
|
from database.utils.caches import CacheManager
|
||||||
from didier.data.embeds.error_embed import create_error_embed
|
from didier.data.embeds.error_embed import create_error_embed
|
||||||
|
from didier.data.embeds.logging_embed import create_logging_embed
|
||||||
from didier.data.embeds.schedules import Schedule, parse_schedule
|
from didier.data.embeds.schedules import Schedule, parse_schedule
|
||||||
from didier.exceptions import HTTPException, NoMatch
|
from didier.exceptions import HTTPException, NoMatch
|
||||||
from didier.utils.discord.prefix import get_prefix
|
from didier.utils.discord.prefix import get_prefix
|
||||||
|
@ -181,15 +182,16 @@ class Didier(commands.Bot):
|
||||||
async def _log(self, level: int, message: str, log_to_discord: bool = True):
|
async def _log(self, level: int, message: str, log_to_discord: bool = True):
|
||||||
"""Log a message to the logging file, and optionally to the configured channel"""
|
"""Log a message to the logging file, and optionally to the configured channel"""
|
||||||
methods = {
|
methods = {
|
||||||
|
logging.DEBUG: logger.debug,
|
||||||
logging.ERROR: logger.error,
|
logging.ERROR: logger.error,
|
||||||
|
logging.INFO: logger.info,
|
||||||
logging.WARNING: logger.warning,
|
logging.WARNING: logger.warning,
|
||||||
}
|
}
|
||||||
|
|
||||||
methods.get(level, logger.error)(message)
|
methods.get(level, logger.error)(message)
|
||||||
if log_to_discord:
|
if log_to_discord:
|
||||||
# TODO pretty embed
|
embed = create_logging_embed(level, message)
|
||||||
# different colours per level?
|
await self.error_channel.send(embed=embed)
|
||||||
await self.error_channel.send(message)
|
|
||||||
|
|
||||||
async def log_error(self, message: str, log_to_discord: bool = True):
|
async def log_error(self, message: str, log_to_discord: bool = True):
|
||||||
"""Log an error message"""
|
"""Log an error message"""
|
||||||
|
|
Loading…
Reference in New Issue