From c10a35b6c08d390ca413cf59aae77c0b1196c555 Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 30 Aug 2018 14:32:59 +0100 Subject: [PATCH] Log exceptions when calling events --- EventManager.py | 6 ++---- IRCLogging.py | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/EventManager.py b/EventManager.py index abb0a454..66006934 100644 --- a/EventManager.py +++ b/EventManager.py @@ -137,10 +137,8 @@ class EventHook(object): 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()) + self.bot.log.error("failed to call event \"%s", [ + event_path], exc_info=True) called += 1 end = time.monotonic() diff --git a/IRCLogging.py b/IRCLogging.py index 7b01acee..c2fbde1c 100644 --- a/IRCLogging.py +++ b/IRCLogging.py @@ -33,15 +33,15 @@ class Log(object): file_handler.setFormatter(formatter) self.logger.addHandler(file_handler) - def debug(self, message, params): - self._log(message, params, logging.DEBUG) - def info(self, message, params): - self._log(message, params, logging.INFO) - def warn(self, message, params): - self._log(message, params, logging.WARN) - def error(self, message, params): - self._log(message, params, logging.ERROR) - def critical(self, message, params): - self._log(message, params, logging.CRITICAL) - def _log(self, message, params, level): - self.logger.log(level, message, *params) + def debug(self, message, params, **kwargs): + self._log(message, params, logging.DEBUG, kwargs) + def info(self, message, params, **kwargs): + self._log(message, params, logging.INFO, kwargs) + def warn(self, message, params, **kwargs): + self._log(message, params, logging.WARN, kwargs) + def error(self, message, params, **kwargs): + self._log(message, params, logging.ERROR, kwargs) + def critical(self, message, params, **kwargs): + self._log(message, params, logging.CRITICAL, kwargs) + def _log(self, message, params, level, kwargs): + self.logger.log(level, message, *params, **kwargs)