diff --git a/DrBotIRC.py b/DrBotIRC.py index 44e1d82..f14277f 100644 --- a/DrBotIRC.py +++ b/DrBotIRC.py @@ -29,6 +29,10 @@ import thread from extlib import irclib + +log = logging.getLogger('drbotzo') + + class DrBotzoMethods: """Methods to expose to the XML-RPC server.""" @@ -43,7 +47,6 @@ class DrBotzoMethods: """ self.irc = irc - self.log = logging.getLogger('drbotzo') def echo(self, message): """Just reply to the client, for testing purposes. @@ -121,7 +124,6 @@ class DrBotServerConnection(irclib.ServerConnection): # temporary. hopefully on_welcome() will set this self.nickmask = socket.getfqdn() - self.log = logging.getLogger('drbotzo') self.add_global_handler('welcome', self.on_welcome, 1) @@ -134,11 +136,14 @@ class DrBotServerConnection(irclib.ServerConnection): """ + log.debug("welcome: {0:s}".format(what)) + what = event.arguments()[0] match = re.search('(\S+!\S+@\S+)', what) if match: self.nickmask = match.group(1) + log.debug("nickmask: {0:s}".format(self.nickmask)) def privmsg(self, target, text): """Send a PRIVMSG command. @@ -149,6 +154,8 @@ class DrBotServerConnection(irclib.ServerConnection): """ + log.debug("OUTGOING PRIVMSG: t[{0:s}] m[{1:s}]".format(target, text)) + splitter = "..." # split messages that are too long. Max length is 512. @@ -196,7 +203,6 @@ class DrBotIRC(irclib.IRC): self.config = config self.xmlrpc = None - self.log = logging.getLogger('drbotzo') # handle SIGINT signal.signal(signal.SIGINT, self.sigint_handler) @@ -238,6 +244,10 @@ class DrBotIRC(irclib.IRC): """ + log.debug("EVENT: e[{0:s}] s[{1:s}] t[{2:s}] " + "a[{3:s}]".format(event.eventtype(), event.source(), + event.target(), event.arguments())) + try: nick = irclib.nm_to_n(event.source()) except (IndexError, AttributeError): @@ -247,7 +257,7 @@ class DrBotIRC(irclib.IRC): if self.config.has_section('Ignore'): alias = self.config.get('Ignore', nick.lower()) if alias: - self.log.debug("ignoring " + nick + " as per config file") + log.debug("ignoring {0:s} as per config file".format(nick)) return except NoOptionError: pass @@ -261,8 +271,8 @@ class DrBotIRC(irclib.IRC): if handler[1](connection, event) == "NO MORE": return except Exception as e: - self.log.error("exception floated up to DrBotIrc!") - self.log.exception(e) + log.error("exception floated up to DrBotIrc!") + log.exception(e) def xmlrpc_register_function(self, func, name): """Add a method to the XML-RPC interface. @@ -487,9 +497,9 @@ class DrBotIRC(irclib.IRC): module.shutdown() connection.quit(msg) - self.log.info(self.save_config()) + log.info(self.save_config()) self._xmlrpc_shutdown() - self.log.info("Bot shutting down.") + log.info("Bot shutting down.") sys.exit() def reply(self, connection, event, replystr, stop=False): @@ -581,8 +591,8 @@ class DrBotIRC(irclib.IRC): return 'Module ' + modname + ' loaded.' except ImportError as e: - self.log.error("Error loading " + modname) - self.log.exception(e) + log.error("Error loading '{0:s}'".format(modname)) + log.exception(e) return "Module '" + modname + "' could not be loaded." def unload_module(self, modname): @@ -642,7 +652,7 @@ class DrBotIRC(irclib.IRC): module.save() module.shutdown() - self.log.info(self.save_config()) + log.info(self.save_config()) self._xmlrpc_shutdown() sys.exit()