make logging output shorter

This commit is contained in:
Seth Schoen 2012-11-18 22:32:58 -08:00
parent 97ea1082ef
commit 2d6af52d21
3 changed files with 9 additions and 3 deletions

View file

@ -51,6 +51,12 @@ def safe(what, s):
else:
return False
def short(thing):
"""Return the first 8 bytes of a session ID, or, for a
challenge ID, the challenge ID with the session ID truncated."""
tmp = thing.partition(":")
return tmp[0][:8] + ".." + tmp[1] + tmp[2]
sessions = redis.Redis()
class session(object):
@ -367,7 +373,7 @@ class session(object):
# TODO: Process challenge-related messages from the client.
def log(self, msg):
sessions.publish("logs", "%s: %s" % (self.id, msg))
sessions.publish("logs", "%s: %s" % (short(self.id), msg))
if debug: print "%s: %s" % (self.id, msg)
def die(self, r, reason, uri=None):

View file

@ -51,7 +51,7 @@ def makechallenge(session):
r.hset(challenge, "dvsni:ext", "1.3.3.7")
# Keep accurate count of how many challenges exist in this session.
r.hincrby(session, "challenges", 1)
log("created new challenge %s" % challenge, session)
log("created new challenge %s" % short(challenge), session)
if True: # challenges have been created
r.hset(session, "state", "testchallenge")
else:

View file

@ -49,7 +49,7 @@ def testchallenge(session):
all_satisfied = True
for i, name in enumerate(r.lrange("%s:names" % session, 0, -1)):
challenge = "%s:%d" % (session, i)
log("testing challenge %s" % challenge, session)
log("testing challenge %s" % short(challenge), session)
challtime = int(r.hget(challenge, "challtime"))
challtype = int(r.hget(challenge, "type"))
name = r.hget(challenge, "name")