implemented error logging to EventManager (WIP)

This commit is contained in:
jesopo 2016-07-14 00:42:17 +01:00
parent 5f8d51cbf0
commit c55982b11f
No known key found for this signature in database
GPG key ID: 0BBDEB2AEFCFFCB3
2 changed files with 15 additions and 4 deletions

View file

@ -1,8 +1,9 @@
import traceback
class Event(object):
def __init__(self, bot, subevent, **kwargs):
def __init__(self, bot, name, **kwargs):
self.bot = bot
self.subevent = subevent
self.name = name
self.kwargs = kwargs
self.eaten = False
def __getitem__(self, key):
@ -68,7 +69,14 @@ class EventHook(object):
break
if event.eaten:
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
return returns
def get_child(self, child_name):

View file

@ -11,6 +11,9 @@ class Module(object):
log_level = event.name
timestamp = self.timestamp()
message = event["message"]
data = event.get("data")
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))
if data:
log_file.write("%s\n" % data)