From 6902e2a80cb9cea535bbe99d34839a3f65f5111c Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Wed, 17 Jan 2018 00:01:49 +0100 Subject: [PATCH] improve debug output --- hbd | 10 +++++++--- hbdclass.py | 9 ++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/hbd b/hbd index 4689ffa..3d19ddc 100755 --- a/hbd +++ b/hbd @@ -316,8 +316,9 @@ def checkoverdue(): def log(host, m, service=None): - if DEBUG > 0: print "Log: %s" % m - ts = time.strftime("%b %d %H:%M:%S", time.localtime(time.time())) + if DEBUG > 0: print "Log: %s %s" % (host, m) + now = time.time() + ts = time.strftime("%b %d %H:%M:%S", time.localtime(now)) if service: srv = "service %s: " % service else: @@ -374,6 +375,7 @@ def readsock(sock): name = shortname(msg.get('name', "unknown")) if not name in Host.hosts: # was: hosts.has_key(name): host = Host(name) + host.dyn = h in dyndnshosts if verbose: print "XX: New host, num now %s" % (len(Host.hosts)) newh=True else: @@ -612,6 +614,7 @@ class HttpHandler(BaseHTTPServer.BaseHTTPRequestHandler): code, res=self.builderror(400, 'Data error', "h=%s not found" % uname) else: log(uname, "dropped") +# for addr in Host.hosts[uname].0i del Host.hosts[uname] res=self.buildhead() res.append("Done") @@ -884,7 +887,8 @@ if 1 and os.path.exists(pickfile): except: lastfm = ["","",""] pickf.close() - except: + except Exception as e: + print "load pickled failed: %s" % e os.unlink(pickfile) Connection.htab = {} for h in Host.hosts.keys(): diff --git a/hbdclass.py b/hbdclass.py index b131354..0355b25 100644 --- a/hbdclass.py +++ b/hbdclass.py @@ -13,7 +13,13 @@ num = 0 MAXRTTS = 10 -# +DEBUG=1 + +def log(host, m): + if DEBUG: + print "class log: %s %s" % (host, m) + + class Connection: # map of addrs to names @@ -38,6 +44,7 @@ class Connection: r = "new addr %s" % (addr) Connection.htab[addr] = self.host.name if self.host.isDynDns(): + log(self.host.name, "dns update %s" % self.addr) Host.dnsQ.put((self.host.name, self.addr)) def registerDns(self):