From 355f5ce2e6f176a9b46427c940f0ecb6732ab7a4 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Sun, 10 Nov 2013 18:28:22 +1300 Subject: [PATCH] stuff --- core/bot.py | 10 +++++----- core/loader.py | 4 ++-- core/main.py | 23 +++++++++++++++-------- core/permissions.py | 3 --- plugins/log.py | 2 +- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/core/bot.py b/core/bot.py index b963c7c..623992b 100644 --- a/core/bot.py +++ b/core/bot.py @@ -32,12 +32,12 @@ def get_logger(): # stdout handler sh = logging.StreamHandler() - sh.setLevel(logging.INFO) + sh.setLevel(logging.DEBUG) # create a formatter and set the formatter for the handler. frmt = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s') fh.setFormatter(frmt) - simple_frmt = logging.Formatter('%(message)s') + simple_frmt = logging.Formatter('[%(levelname)s] %(message)s') sh.setFormatter(simple_frmt) # add the Handlers to the logger @@ -99,23 +99,23 @@ class Bot(threading.Thread): """create the logger and config objects""" # logging self.logger = get_logger() - self.logger.debug("Logging engine started.") + self.logger.debug("Logging system ready.") # data folder self.data_dir = os.path.abspath('persist') if not os.path.exists(self.data_dir): self.logger.debug("Data folder not found, creating.") os.mkdir(self.data_dir) - self.logger.debug("Created data folder.") # config self.config = config.Config(self) - self.logger.debug("Config object created.") + self.logger.debug("Config system ready.") # db engine = create_engine('sqlite:///cloudbot.db') db_factory = sessionmaker(bind=engine) self.db_session = scoped_session(db_factory) + self.logger.debug("Database system ready.") def connect(self): diff --git a/core/loader.py b/core/loader.py index d042f60..b1e301e 100644 --- a/core/loader.py +++ b/core/loader.py @@ -70,8 +70,8 @@ class PluginLoader(object): namespace = {} eval(code, namespace) except Exception: - self.bot.logger.error("Error compiling {}:".format(filename)) - self.bot.logger.error(traceback.format_exc()) + self.bot.logger.exception("Error compiling {}:".format(filename)) + #self.bot.logger.error(traceback.format_exc()) return # remove plugins already loaded from this file diff --git a/core/main.py b/core/main.py index 7c69332..f083feb 100755 --- a/core/main.py +++ b/core/main.py @@ -53,7 +53,7 @@ class Input(dict): self[key] = value -def run(func, input): +def run(func, input, bot): args = func._args uses_db = 'db' in args and 'db' not in input @@ -68,12 +68,21 @@ def run(func, input): if 'input' in args: input.input = input if 0 in args: - out = func(input.inp, **input) + try: + out = func(input.inp, **input) + except: + bot.logger.exception("Error in plugin {}:".format(func._filename)) else: kw = dict((key, input[key]) for key in args if key in input) - out = func(input.inp, **kw) + try: + out = func(input.inp, **kw) + except: + bot.logger.exception("Error in plugin {}:".format(func._filename)) else: - out = func(input.inp) + try: + out = func(input.inp) + except: + bot.logger.exception("Error in plugin {}:".format(func._filename)) if out is not None: input.reply(unicode(out)) @@ -114,9 +123,7 @@ class Handler(object): try: run(self.func, input) except: - import traceback - - traceback.print_exc() + self.bot.logger.exception("Error in plugin {}:".format(self.Sfunc._filename)) def stop(self): self.input_queue.put(StopIteration) @@ -138,7 +145,7 @@ def dispatch(bot, input, kind, func, args, autohelp=False): if func._thread: bot.threads[func].put(input) else: - thread.start_new_thread(run, (func, input)) + thread.start_new_thread(run, (func, input, bot)) def match_command(bot, command): diff --git a/core/permissions.py b/core/permissions.py index 4ff3404..22ff500 100644 --- a/core/permissions.py +++ b/core/permissions.py @@ -19,9 +19,6 @@ class PermissionManager(object): self.perm_users = {} self.reload() - print self.group_perms - print self.group_users - print self.perm_users def reload(self): self.logger.info("Reloading permissions for {}.".format(self.conn.name)) diff --git a/plugins/log.py b/plugins/log.py index eafed3e..ef783fd 100755 --- a/plugins/log.py +++ b/plugins/log.py @@ -113,4 +113,4 @@ def log(paraml, input=None, bot=None): out = "{} {} {}".format(timestamp, input.chan, beau.encode('utf8', 'ignore')) - sys.stdout.write(out + os.linesep) + print out