aboutsummaryrefslogtreecommitdiff
path: root/rpkid/rpki/log.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2012-08-29 20:55:58 +0000
committerRob Austein <sra@hactrn.net>2012-08-29 20:55:58 +0000
commite252a23ca2502fa83d234bb4491efae02aeec30d (patch)
tree62a8bf04621d2e2d5dfbfb9aedbec79d8ca4b30f /rpkid/rpki/log.py
parent3e72d90ded7b35d3b292acfd1989c0ebe45174d6 (diff)
Add a lot of __repr__() methods in an attempt to make the logs more
useful. Add rpki.sql.cache_reference decorator, to give the garbage collector some guidance about linkages between active objects now that the SQL cache uses weak references. Other minor cleanup. svn path=/branches/tk274/; revision=4676
Diffstat (limited to 'rpkid/rpki/log.py')
-rw-r--r--rpkid/rpki/log.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/rpkid/rpki/log.py b/rpkid/rpki/log.py
index 1f323a36..7c20c3c1 100644
--- a/rpkid/rpki/log.py
+++ b/rpkid/rpki/log.py
@@ -44,7 +44,6 @@ try:
except ImportError:
have_setproctitle = False
-
## @var enable_trace
# Whether call tracing is enabled.
@@ -72,6 +71,15 @@ enable_tracebacks = True
use_setproctitle = True
+## @var proctitle_extra
+
+# Extra text to include in proctitle display. By default this is the
+# tail of the current directory name, as this is often useful, but you
+# can set it to something else if you like. If None or the empty
+# string, the extra information field will be omitted from the proctitle.
+
+proctitle_extra = os.path.basename(os.getcwd())
+
tag = ""
pid = 0
@@ -87,7 +95,10 @@ def init(ident = "rpki", flags = syslog.LOG_PID, facility = syslog.LOG_DAEMON):
tag = ident
pid = os.getpid()
if ident and have_setproctitle and use_setproctitle:
- setproctitle.setproctitle("%s (%s)" % (ident, os.path.basename(os.getcwd())))
+ if proctitle_extra:
+ setproctitle.setproctitle("%s (%s)" % (ident, proctitle_extra))
+ else:
+ setproctitle.setproctitle(ident)
def set_trace(enable):
"""
@@ -165,7 +176,15 @@ def log_repr(obj, *tokens):
words.append("{%s}" % obj.self.self_handle)
except:
pass
- words.extend(str(token) for token in tokens if token is not None and token != "")
+ for token in tokens:
+ if token is not None and token != "":
+ try:
+ assert token is not None
+ words.append(str(token))
+ except:
+ debug("Failed to generate repr() string for object of type %r" % type(token))
+ traceback()
+ words.append("???")
if show_python_ids:
words.append(" at %#x" % id(obj))
return "<" + " ".join(words) + ">"