📝 Better Logging
This commit is contained in:
@ -30,7 +30,10 @@ class ErrorHandler():
|
||||
|
||||
exceptionString = "".join(exception)
|
||||
self.bot.log([f"exception in /{ctx.name}", f"{exceptionString}"],str(ctx.channel_id), 40)
|
||||
await ctx.send("Something went wrong (error code 000)")
|
||||
if isinstance(error, discord.errors.NotFound):
|
||||
self.bot.log("Context is non-existant", level = 40)
|
||||
else:
|
||||
await ctx.send("Something went wrong (error code 000)")
|
||||
|
||||
async def on_error(self, method):
|
||||
exception = traceback.format_exc()
|
||||
|
@ -1,11 +1,21 @@
|
||||
import json
|
||||
import time
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from .helperClasses import Options
|
||||
|
||||
FORMAT = " %(asctime)s | %(name)-16s | %(levelname)-8s | %(message)s"
|
||||
PRINTFORMAT = "%(asctime)s - %(message)s"
|
||||
DATEFORMAT = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
logging.addLevelName(25, "PRINT")
|
||||
logging.basicConfig(filename="gwendolyn.log", level=logging.INFO)
|
||||
logging.basicConfig(format=FORMAT, datefmt=DATEFORMAT, level=logging.INFO, filename="gwendolyn.log")
|
||||
logger = logging.getLogger("Gwendolyn")
|
||||
printer = logging.getLogger("printer")
|
||||
handler = logging.StreamHandler(sys.stdout)
|
||||
handler.setFormatter(logging.Formatter(fmt = PRINTFORMAT, datefmt=DATEFORMAT))
|
||||
printer.addHandler(handler)
|
||||
printer.propagate = False
|
||||
|
||||
def getParams():
|
||||
with open("resources/slashParameters.json", "r") as f:
|
||||
@ -20,25 +30,24 @@ def getParams():
|
||||
return params
|
||||
|
||||
def logThis(messages, channel : str = "", level : int = 20):
|
||||
localtime = time.asctime(time.localtime(time.time()))
|
||||
channel = channel.replace("Direct Message with ","")
|
||||
if type(messages) is str:
|
||||
messages = [messages]
|
||||
|
||||
printMessage = messages[0]
|
||||
|
||||
for x, msg in enumerate(messages):
|
||||
if channel == "":
|
||||
messages[x] = localtime+" - "+msg
|
||||
else:
|
||||
messages[x] = localtime+" ("+channel+") - "+msg
|
||||
if channel != "":
|
||||
messages[x] = f"{msg} - ({channel})"
|
||||
|
||||
if len(messages) > 1:
|
||||
messages[0] += " (details in log)"
|
||||
printMessage += " (details in log)"
|
||||
|
||||
if level >= 25:
|
||||
print(messages[0])
|
||||
printer.log(level, printMessage)
|
||||
|
||||
for logMessage in messages:
|
||||
logging.log(level, logMessage)
|
||||
logger.log(level, logMessage)
|
||||
|
||||
# Capitalizes all words except some of them
|
||||
def cap(s):
|
||||
|
Reference in New Issue
Block a user