This commit is contained in:
LBlend committed 2022-11-14 02:39:24 +01:00
1 parent 32de2b8de6
commit 8f2fa2ab2d
3 files changed
+20 -10

No files matched your search

+3 -9
View File
@@ -19,7 +19,7 @@ class Errors(commands.Cog):
Prints command execution metadata
"""
print(
self.bot.logger.info(
f'{datetime.now().strftime("%Y-%m-%d %H:%M:%S")} | ' +
f'{"❌ " if ctx.command_failed else "✔ "} {ctx.command} - ' +
f'{ctx.author.name}#{ctx.author.discriminator} ({ctx.author.id}) | ' +
@@ -92,14 +92,8 @@ class Errors(commands.Cog):
embed = embed_templates.error_fatal(ctx, text='En ukjent feil oppstod!')
await ctx.send(embed=embed)
# Print full exception to console
print(f'Ignoring exception in command {ctx.command}:', file=sys.stderr)
traceback.print_exception(
type(error),
error,
error.__traceback__,
file=sys.stderr
)
# Log full exception to file
self.bot.logger.error(''.join(traceback.format_exception(type(error), error, error.__traceback__)))
async def setup(bot):
+14
View File
@@ -0,0 +1,14 @@
import logging
import logging.handlers
class BotLogger:
def __init__(self):
logger = logging.getLogger('discord')
logger.setLevel(logging.INFO)
handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
formatter = logging.Formatter('[{asctime}] [{levelname:<8}] {name}: {message}', '%Y-%m-%d %H:%M:%S', style='{')
handler.setFormatter(formatter)
logger.addHandler(handler)
self.logger = logger
+3 -1
View File
@@ -8,6 +8,7 @@ from os import listdir
import locale
from time import time
import psycopg2
from logger import BotLogger
locale.setlocale(locale.LC_ALL, "")
@@ -23,6 +24,7 @@ class Bot(commands.Bot):
super().__init__(
command_prefix=commands.when_mentioned_or(config["bot"]["prefix"]), case_insensitive=True, intents=intents
)
self.logger = BotLogger().logger
self.prefix = config["bot"]["prefix"]
self.presence = config["bot"].get("presence", {})
@@ -81,4 +83,4 @@ async def on_ready():
)
bot.run(config["bot"]["token"], reconnect=True)
bot.run(config["bot"]["token"], reconnect=True, log_handler=None)