diff options
author | Rob Austein <sra@hactrn.net> | 2011-04-27 04:34:52 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2011-04-27 04:34:52 +0000 |
commit | 744ec2cb899c6237d70c1126dc4295f86f69ca73 (patch) | |
tree | 812738b96bbb62acad324411e26c9989eb478a24 /rpkid/rpki/log.py | |
parent | 927c896cfb35ceefbfb476a7681a9dade6509b81 (diff) |
First whack at some of the silliest logging code
svn path=/rpkid/rpki/async.py; revision=3793
Diffstat (limited to 'rpkid/rpki/log.py')
-rw-r--r-- | rpkid/rpki/log.py | 17 |
1 files changed, 17 insertions, 0 deletions
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) + ">" |