From 54dff7a15addb6f750bf0e7d06e8bd18a9a4882f Mon Sep 17 00:00:00 2001 From: James Lu Date: Sun, 5 Jul 2015 13:29:01 -0700 Subject: [PATCH] Convert print() calls to log calls, Round 1 --- main.py | 16 ++++++++-------- protocols/inspircd.py | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/main.py b/main.py index 2049ae7..d7b79cc 100755 --- a/main.py +++ b/main.py @@ -35,7 +35,7 @@ class Irc(): ip = self.serverdata["ip"] port = self.serverdata["port"] self.sid = self.serverdata["sid"] - log.info("Connecting to network %r on %s:%s" % (self.name, ip, port)) + log.info("Connecting to network %r on %s:%s", self.name, ip, port) self.socket = socket.socket() self.socket.connect((ip, port)) @@ -57,16 +57,16 @@ class Irc(): break while '\n' in buf: line, buf = buf.split('\n', 1) - log.debug("<- {}".format(line)) + log.debug("<- %s", line) proto.handle_events(self, line) except socket.error as e: - log.error('Received socket.error: %s, exiting.' % str(e)) + log.error('Received socket.error: %s, exiting.', str(e)) break sys.exit(1) def send(self, data): data = data.encode("utf-8") + b"\n" - log.debug("-> {}".format(data.decode("utf-8").strip("\n"))) + log.debug("-> %s", data.decode("utf-8").strip("\n")) self.socket.send(data) def load_plugins(self): @@ -80,9 +80,9 @@ class Irc(): self.loaded.append(imp.load_source(plugin, moduleinfo[1])) except ImportError as e: if str(e).startswith('No module named'): - log.error('Failed to load plugin %r: the plugin could not be found.' % plugin) + log.error('Failed to load plugin %r: the plugin could not be found.', plugin) else: - log.error('Failed to load plugin %r: import error %s' % (plugin, str(e))) + log.error('Failed to load plugin %r: import error %s', plugin, str(e)) print("loaded plugins: %s" % self.loaded) if __name__ == '__main__': @@ -98,9 +98,9 @@ if __name__ == '__main__': proto = imp.load_source(protoname, moduleinfo[1]) except ImportError as e: if str(e).startswith('No module named'): - log.critical('Failed to load protocol module %r: the file could not be found.' % protoname) + log.critical('Failed to load protocol module %r: the file could not be found.', protoname) else: - log.critical('Failed to load protocol module: import error %s' % (protoname, str(e))) + log.critical('Failed to load protocol module: import error %s', protoname, str(e)) sys.exit(2) else: irc_obj = Irc(proto) diff --git a/protocols/inspircd.py b/protocols/inspircd.py index df737b5..c83c57d 100644 --- a/protocols/inspircd.py +++ b/protocols/inspircd.py @@ -78,9 +78,9 @@ def removeClient(irc, numeric): for v in irc.channels.values(): v.removeuser(numeric) sid = numeric[:3] - print('Removing client %s from irc.users' % numeric) + log.debug('Removing client %s from irc.users', numeric) del irc.users[numeric] - print('Removing client %s from irc.servers[%s]' % (numeric, sid)) + log.debug('Removing client %s from irc.servers[%s]', numeric, sid) irc.servers[sid].users.remove(numeric) def quitClient(irc, numeric, reason): @@ -221,7 +221,7 @@ def handle_uid(irc, numeric, command, args): realname = args[-1] irc.users[uid] = IrcUser(nick, ts, uid, ident, host, realname, realhost, ip) parsedmodes = utils.parseModes(irc, uid, [args[8], args[9]]) - print('Applying modes %s for %s' % (parsedmodes, uid)) + log.debug('Applying modes %s for %s', parsedmodes, uid) utils.applyModes(irc, uid, parsedmodes) irc.servers[numeric].users.append(uid) return {'uid': uid, 'ts': ts, 'nick': nick, 'realhost': realhost, 'host': host, 'ident': ident, 'ip': ip} @@ -286,15 +286,15 @@ def handle_mode(irc, numeric, command, args): def handle_squit(irc, numeric, command, args): # :70M SQUIT 1ML :Server quit by GL!gl@0::1 split_server = args[0] - print('Netsplit on server %s' % split_server) + log.info('(%s) Netsplit on server %s', irc.name, split_server) # Prevent RuntimeError: dictionary changed size during iteration old_servers = copy(irc.servers) for sid, data in old_servers.items(): if data.uplink == split_server: - print('Server %s also hosts server %s, removing those users too...' % (split_server, sid)) + log.debug('Server %s also hosts server %s, removing those users too...', split_server, sid) handle_squit(irc, sid, 'SQUIT', [sid, "PyLink: Automatically splitting leaf servers of %s" % sid]) for user in copy(irc.servers[split_server].users): - print('Removing client %s (%s)' % (user, irc.users[user].nick)) + log.debug('Removing client %s (%s)', user, irc.users[user].nick) removeClient(irc, user) del irc.servers[split_server] return {'target': split_server}