[or-cvs] r17431: {updater} Make controller logging work better on python 2.4 (where the (updater/trunk/lib/thandy)

nickm at seul.org nickm at seul.org
Mon Dec 1 16:08:12 UTC 2008


Author: nickm
Date: 2008-12-01 11:08:12 -0500 (Mon, 01 Dec 2008)
New Revision: 17431

Modified:
   updater/trunk/lib/thandy/ClientCLI.py
   updater/trunk/lib/thandy/repository.py
   updater/trunk/lib/thandy/util.py
Log:
Make controller logging work better on python 2.4 (where the "extra" feature of logger.log does not exist.)

Modified: updater/trunk/lib/thandy/ClientCLI.py
===================================================================
--- updater/trunk/lib/thandy/ClientCLI.py	2008-12-01 16:01:59 UTC (rev 17430)
+++ updater/trunk/lib/thandy/ClientCLI.py	2008-12-01 16:08:12 UTC (rev 17431)
@@ -22,22 +22,14 @@
 json = thandy.util.importJSON()
 
 class ControlLogFormatter:
-    def _formatStr(self, s):
-        s = '"%s"' % re.sub(r'(["\\])', r'\\\1', s)
-        s = s.replace("\n", "\\n")
-        return s
-
     def format(self, record):
         name = record.name
         if name == 'thandy-ctrl':
-            parts = [ record.msg ]
-            parts.extend(
-                "%s=%s"%(k, self._formatStr(v))
-                for k,v in sorted(getattr(record, 'cmd_args', {}).iteritems()))
-            return " ".join(parts)
+            return record.getMessage()
         else:
             m = record.getMessage()
-            return "%s msg=%s"%(record.levelname, self._formatStr(m))
+            return "%s msg=%s"%(record.levelname,
+                                thandy.util.formatLogString(m))
 
     def formatException(self, exc_info):
         return repr(traceback.print_exception())

Modified: updater/trunk/lib/thandy/repository.py
===================================================================
--- updater/trunk/lib/thandy/repository.py	2008-12-01 16:01:59 UTC (rev 17430)
+++ updater/trunk/lib/thandy/repository.py	2008-12-01 16:08:12 UTC (rev 17431)
@@ -321,7 +321,6 @@
             try:
                 f.load()
             except OSError, e:
-                print "need", f.getPath()
                 logging.info("Couldn't load %s: %s.  Must fetch it.",
                              f.getPath(), e)
                 need.add(f.getRelativePath())

Modified: updater/trunk/lib/thandy/util.py
===================================================================
--- updater/trunk/lib/thandy/util.py	2008-12-01 16:01:59 UTC (rev 17430)
+++ updater/trunk/lib/thandy/util.py	2008-12-01 16:08:12 UTC (rev 17431)
@@ -2,6 +2,7 @@
 
 import logging
 import os
+import re
 import sys
 import tempfile
 import random
@@ -198,7 +199,15 @@
 
 _controlLog = logging.getLogger("thandy-ctrl")
 
+def formatLogString(s):
+    s = '"%s"' % re.sub(r'(["\\])', r'\\\1', s)
+    s = s.replace("\n", "\\n")
+    return s
+
 def logCtrl(key, **args):
     """DOCDOC"""
-    _controlLog.log(logging.INFO, key, extra={'cmd_args':args})
+    parts = [ key ]
+    parts.extend(
+        "%s=%s"%(k, formatLogString(v)) for k,v in sorted(args.iteritems()))
+    _controlLog.log(logging.INFO, " ".join(parts))
 



More information about the tor-commits mailing list