From 744ec2cb899c6237d70c1126dc4295f86f69ca73 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Wed, 27 Apr 2011 04:34:52 +0000 Subject: First whack at some of the silliest logging code svn path=/rpkid/rpki/async.py; revision=3793 --- rpkid/rpki/log.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'rpkid/rpki/log.py') diff --git a/rpkid/rpki/log.py b/rpkid/rpki/log.py index 9d346385..658ee984 100644 --- a/rpkid/rpki/log.py +++ b/rpkid/rpki/log.py @@ -45,6 +45,11 @@ enable_trace = False use_syslog = True +## @var show_python_ids +# Whether __repr__() methods should show Python id numbers + +show_python_ids = False + tag = "" pid = 0 @@ -109,3 +114,15 @@ def traceback(): assert bt is not None, "Apparently I'm still not using the right test for null backtrace" for line in bt.splitlines(): warn(line) + +def log_repr(obj, *tokens): + """ + Constructor for __repr__() strings, handles suppression of Python + IDs as needed. + """ + + words = ["%s.%s" % (obj.__class__.__module__, obj.__class__.__name__)] + words.extend(str(token) for token in tokens if token is not None and token != "") + if show_python_ids: + words.append(" at %#x" % id(obj)) + return "<" + " ".join(words) + ">" -- cgit v1.2.3