From f657b389ab3c8f67c08ea8ee51af012da768f04a Mon Sep 17 00:00:00 2001 From: NikolajDanger Date: Sun, 28 Mar 2021 10:51:29 +0200 Subject: [PATCH] :pencil: Better logging --- Gwendolyn.py | 2 +- funcs/miscFuncs.py | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Gwendolyn.py b/Gwendolyn.py index a804f9c..a07cafd 100644 --- a/Gwendolyn.py +++ b/Gwendolyn.py @@ -93,7 +93,7 @@ async def on_command_error(ctx, error): exception = exception[:index] exceptionString = "".join(exception) - logThis(f"exception in command !{ctx.command}, {exceptionString}",str(ctx.message.channel.id)) + logThis([f"exception in command !{ctx.command}", f"{exceptionString}"],str(ctx.message.channel.id), 40) await ctx.send("Something went wrong (error code 000)") #Loads cogs diff --git a/funcs/miscFuncs.py b/funcs/miscFuncs.py index 7128381..c55f23d 100644 --- a/funcs/miscFuncs.py +++ b/funcs/miscFuncs.py @@ -1,3 +1,4 @@ +from typing import Union import lxml.etree # Used by imageFunc import datetime # Used by helloFunc import json # Used by spellFunc @@ -100,15 +101,22 @@ def imageFunc(): logThis("Couldn't connect to bing (error code 701)") return(image) -def logThis(message : str, channel = ""): +def logThis(messages : Union[str, list], channel = "", level = 20): localtime = time.asctime(time.localtime(time.time())) channel = channel.replace("Direct Message with ","") - if channel == "": - print(localtime+" - "+message) - logging.info(localtime+" - "+message) - else: - print(localtime+" ("+channel+") - "+message) - logging.info(localtime+" ("+channel+") - "+message) + if type(messages) is str: + messages = [messages] + + for x, msg in enumerate(messages): + if channel == "": + messages[x] = localtime+" - "+msg + else: + messages[x] = localtime+" ("+channel+") - "+msg + + print(messages[0]) + + for logMessage in messages: + logging.log(level, logMessage) # Finds a page from the Senkulpa Wikia def findWikiPage(search : str):