[CalendarServer-changes] [13235] twext/trunk/twext/python/log.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Apr 9 18:43:24 PDT 2014


Revision: 13235
          http://trac.calendarserver.org//changeset/13235
Author:   wsanchez at apple.com
Date:     2014-04-09 18:43:23 -0700 (Wed, 09 Apr 2014)
Log Message:
-----------
svn commit

Modified Paths:
--------------
    twext/trunk/twext/python/log.py

Modified: twext/trunk/twext/python/log.py
===================================================================
--- twext/trunk/twext/python/log.py	2014-04-10 01:31:10 UTC (rev 13234)
+++ twext/trunk/twext/python/log.py	2014-04-10 01:43:23 UTC (rev 13235)
@@ -938,40 +938,51 @@
         if moduleName is __name__:
             continue
 
-        for name, obj in module.__dict__.iteritems():
-            try:
-                newLogger = Logger(namespace=module.__name__)
-            except AttributeError:
-                # Can't look up __name__.  A hack in the "six" module causes
-                # this.  Skip the module.
-                # See https://trac.calendarserver.org/ticket/832
-                continue
+        try:
+            for name, obj in module.__dict__.iteritems():
+                try:
+                    newLogger = Logger(namespace=module.__name__)
+                except AttributeError:
+                    # Can't look up __name__.  A hack in the "six" module causes
+                    # this.  Skip the module.
+                    # See https://trac.calendarserver.org/ticket/832
+                    continue
 
-            legacyLogger = LegacyLogger(logger=newLogger)
+                legacyLogger = LegacyLogger(logger=newLogger)
 
-            if obj is twisted.python.log:
-                log.info(
-                    "Replacing Twisted log module object {0} in {1}"
-                    .format(name, module.__name__)
-                )
-                setattr(module, name, legacyLogger)
+                if obj is twisted.python.log:
+                    log.info(
+                        "Replacing Twisted log module object {0} in {1}"
+                        .format(name, module.__name__)
+                    )
+                    setattr(module, name, legacyLogger)
 
-            elif obj is twisted.python.log.msg:
-                log.info(
-                    "Replacing Twisted log.msg object {0} in {1}"
-                    .format(name, module.__name__)
-                )
-                setattr(module, name, legacyLogger.msg)
+                elif obj is twisted.python.log.msg:
+                    log.info(
+                        "Replacing Twisted log.msg object {0} in {1}"
+                        .format(name, module.__name__)
+                    )
+                    setattr(module, name, legacyLogger.msg)
 
-            elif obj is twisted.python.log.err:
-                log.info(
-                    "Replacing Twisted log.err object {0} in {1}"
-                    .format(name, module.__name__)
-                )
-                setattr(module, name, legacyLogger.err)
+                elif obj is twisted.python.log.err:
+                    log.info(
+                        "Replacing Twisted log.err object {0} in {1}"
+                        .format(name, module.__name__)
+                    )
+                    setattr(module, name, legacyLogger.err)
+        except RuntimeError as e:
+            # Python could use more specific exceptions, eh.
+            # What we mean to catch is:
+            # RuntimeError: dictionary changed size during iteration
+            log.error(
+                "Unable to replace twisted loggers for module {module}: "
+                "{error}",
+                module=module, error=e
+            )
 
 
 
+
 ######################################################################
 # FIXME: This may not be needed; look into removing it.
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140409/f790b677/attachment.html>


More information about the calendarserver-changes mailing list