📝 Better logging

This commit is contained in:
NikolajDanger
2021-03-28 10:51:29 +02:00
parent 552f00ff32
commit f657b389ab
2 changed files with 16 additions and 8 deletions

View File

@ -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):