implemented error logging to EventManager (WIP)
This commit is contained in:
parent
5f8d51cbf0
commit
c55982b11f
2 changed files with 15 additions and 4 deletions
|
@ -1,8 +1,9 @@
|
||||||
|
import traceback
|
||||||
|
|
||||||
class Event(object):
|
class Event(object):
|
||||||
def __init__(self, bot, subevent, **kwargs):
|
def __init__(self, bot, name, **kwargs):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.subevent = subevent
|
self.name = name
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
self.eaten = False
|
self.eaten = False
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
|
@ -68,7 +69,14 @@ class EventHook(object):
|
||||||
break
|
break
|
||||||
if event.eaten:
|
if event.eaten:
|
||||||
break
|
break
|
||||||
returns.append(hook.call(event))
|
try:
|
||||||
|
returns.append(hook.call(event))
|
||||||
|
except Exception as e:
|
||||||
|
traceback.print_exc()
|
||||||
|
# TODO don't make this an event call. can lead to error cycles!
|
||||||
|
self.bot.events.on("log").on("error").call(
|
||||||
|
message="Failed to call event callback",
|
||||||
|
data=traceback.format_exc())
|
||||||
called += 1
|
called += 1
|
||||||
return returns
|
return returns
|
||||||
def get_child(self, child_name):
|
def get_child(self, child_name):
|
||||||
|
|
|
@ -11,6 +11,9 @@ class Module(object):
|
||||||
log_level = event.name
|
log_level = event.name
|
||||||
timestamp = self.timestamp()
|
timestamp = self.timestamp()
|
||||||
message = event["message"]
|
message = event["message"]
|
||||||
|
data = event.get("data")
|
||||||
with open("bot.log", "a") as log_file:
|
with open("bot.log", "a") as log_file:
|
||||||
log_file.write("%s [%s] %s" % (timestamp, log_level,
|
log_file.write("%s [%s] %s\n" % (timestamp, log_level,
|
||||||
message))
|
message))
|
||||||
|
if data:
|
||||||
|
log_file.write("%s\n" % data)
|
||||||
|
|
Loading…
Reference in a new issue