This commit is contained in:
Luke Rogers 2013-11-10 18:28:22 +13:00
parent bae3c819ca
commit 355f5ce2e6
5 changed files with 23 additions and 19 deletions

View file

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

View file

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

View file

@ -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:
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)
try:
out = func(input.inp, **kw)
except:
bot.logger.exception("Error in plugin {}:".format(func._filename))
else:
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):

View file

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

View file

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