irkerd: Replace 'logfile' global with local Irker.logfile
authorW. Trevor King <wking@tremily.us>
Fri, 7 Mar 2014 04:21:11 +0000 (20:21 -0800)
committerEric S. Raymond <esr@thyrsus.com>
Tue, 11 Mar 2014 04:46:00 +0000 (00:46 -0400)
irkerd

diff --git a/irkerd b/irkerd
index f3ee58d948f46b35dad7bcef67c4f663abd6f485..bb54f85bbc1a5710ea46fa4c185838a86be489af 100755 (executable)
--- a/irkerd
+++ b/irkerd
@@ -708,7 +708,8 @@ class Dispatcher:
 
 class Irker:
     "Persistent IRC multiplexer."
-    def __init__(self, **kwargs):
+    def __init__(self, logfile=None, **kwargs):
+        self.logfile = logfile
         self.kwargs = kwargs
         self.irc = IRCClient()
         self.irc.add_event_handler("ping", self._handle_ping)
@@ -746,7 +747,7 @@ class Irker:
             arguments = event.arguments
             for lump in arguments:
                 if lump.startswith("DEAF="):
-                    if not logfile:
+                    if not self.logfile:
                         connection.mode(cxt.nickname(), "+"+lump[5:])
                 elif lump.startswith("MAXCHANNELS="):
                     m = int(lump[12:])
@@ -780,8 +781,8 @@ class Irker:
             connection.context.handle_kick(target)
     def _handle_every_raw_message(self, _connection, event):
         "Log all messages when in watcher mode."
-        if logfile:
-            with open(logfile, "a") as logfp:
+        if self.logfile:
+            with open(self.logfile, "a") as logfp:
                 logfp.write("%03f|%s|%s\n" % \
                              (time.time(), event.source, event.arguments[0]))
     def pending(self):
@@ -929,6 +930,7 @@ if __name__ == '__main__':
         LOG.setLevel(log_level)
 
     irker = Irker(
+        logfile=logfile,
         nick_template=nick_template,
         nick_needs_number=re.search("%.*d", nick_template),
         )