]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
make logging multiple nodes at once easier to follow
authorBrian Warner <warner@lothar.com>
Sun, 3 Dec 2006 03:27:50 +0000 (20:27 -0700)
committerBrian Warner <warner@lothar.com>
Sun, 3 Dec 2006 03:27:50 +0000 (20:27 -0700)
allmydata/client.py
allmydata/node.py
allmydata/queen.py

index 641b2e433d653e26d2a841aa1e023d0e15d0cc06..d9e16a14fcfd17b0b6bb134a232232cb202404e4 100644 (file)
@@ -46,7 +46,7 @@ class Client(node.Node, Referenceable):
         if self.queen_connector:
             return
         if not self.queen_pburl:
-            log.msg("no queen_pburl, cannot connect")
+            self.log("no queen_pburl, cannot connect")
             return
         self.queen_connector = self.tub.connectTo(self.queen_pburl,
                                                   self._got_queen)
@@ -58,14 +58,14 @@ class Client(node.Node, Referenceable):
         return service.MultiService.stopService(self)
 
     def _got_queen(self, queen):
-        log.msg("connected to queen")
+        self.log("connected to queen")
         self.queen = queen
         queen.notifyOnDisconnect(self._lost_queen)
         queen.callRemote("hello",
                          nodeid=self.nodeid, node=self, pburl=self.my_pburl)
 
     def _lost_queen(self):
-        log.msg("lost connection to queen")
+        self.log("lost connection to queen")
         self.queen = None
 
     def remote_get_service(self, name):
@@ -75,25 +75,25 @@ class Client(node.Node, Referenceable):
         for nodeid, pburl in new_peers:
             if nodeid == self.nodeid:
                 continue
-            log.msg("adding peer %s" % idlib.b2a(nodeid))
+            self.log("adding peer %s" % idlib.b2a(nodeid))
             if nodeid in self.all_peers:
                 log.msg("weird, I already had an entry for them")
             self.all_peers.add(nodeid)
             if nodeid not in self.connections:
                 d = self.tub.getReference(pburl)
                 def _got_reference(ref):
-                    log.msg("connected to %s" % idlib.b2a(nodeid))
+                    self.log("connected to %s" % idlib.b2a(nodeid))
                     if nodeid in self.all_peers:
                         self.connections[nodeid] = ref
                 d.addCallback(_got_reference)
 
     def remote_lost_peers(self, lost_peers):
         for nodeid in lost_peers:
-            log.msg("lost peer %s" % idlib.b2a(nodeid))
+            self.log("lost peer %s" % idlib.b2a(nodeid))
             if nodeid in self.all_peers:
                 self.all_peers.remove(nodeid)
             else:
-                log.msg("weird, I didn't have an entry for them")
+                self.log("weird, I didn't have an entry for them")
             if nodeid in self.connections:
                 del self.connections[nodeid]
 
index 7a0d28ad83b2f01a27bd6d3861eee42417444625..1af8a3c3087e909a85d1d0df6f420e5fc6f322c2 100644 (file)
@@ -29,6 +29,7 @@ class Node(service.MultiService):
             f.write(self.tub.getCertData())
             f.close()
         self.nodeid = idlib.a2b(self.tub.tubID)
+        self.short_nodeid = self.tub.tubID[:4] # ready for printing
         portnum = 0
         assert self.PORTNUMFILE, "Your node.Node subclass must provide PORTNUMFILE"
         self._portnumfile = os.path.join(self.basedir, self.PORTNUMFILE)
@@ -48,7 +49,10 @@ class Node(service.MultiService):
                 from allmydata import manhole
                 m = manhole.AuthorizedKeysManhole(portnum, keyfile)
                 m.setServiceParent(self)
-                log.msg("AuthorizedKeysManhole listening on %d" % portnum)
+                self.log("AuthorizedKeysManhole listening on %d" % portnum)
+
+    def log(self, msg):
+        log.msg(self.short_nodeid + ": " + msg)
 
     def _setup_tub(self, local_ip):
         # we can't get a dynamically-assigned portnum until our Tub is
@@ -84,4 +88,4 @@ class Node(service.MultiService):
         local_ip = get_local_ip_for()
         self._setup_tub(local_ip)
         self.tub_ready()
-        log.msg("%s running" % self.NODETYPE)
+        self.log("%s running" % self.NODETYPE)
index dfb299d01eb23a315055e40f7bcb45582393aa39..1c84889f941fd63a7212df6d83d18d5527799c19 100644 (file)
@@ -34,7 +34,7 @@ class Roster(service.MultiService, Referenceable):
                                   new_peers=[(new_nodeid, new_node_pburl)])
 
     def _lost_node(self, nodeid):
-        log.msg("lost contact with %s" % idlib.b2a(nodeid))
+        log.msg("roster: lost contact with %s" % idlib.b2a(nodeid))
         del self.phonebook[nodeid]
         del self.connections[nodeid]
         eventually(self._announce_lost_peer, nodeid)
@@ -57,7 +57,7 @@ class Queen(node.Node):
     def tub_ready(self):
         r = self.add_service(Roster())
         self.urls["roster"] = self.tub.registerReference(r, "roster")
-        log.msg(" roster is at %s" % self.urls["roster"])
+        self.log(" roster is at %s" % self.urls["roster"])
         f = open(os.path.join(self.basedir, "roster_pburl"), "w")
         f.write(self.urls["roster"] + "\n")
         f.close()