[CMF-checkins] SVN: CMF/trunk/CMF Sync logging code with 1.6 branch.

Florent Guillaume fg at nuxeo.com
Thu Jun 8 12:55:13 EDT 2006


Log message for revision 68525:
  Sync logging code with 1.6 branch.

Changed:
  U   CMF/trunk/CMFCore/CMFCatalogAware.py
  U   CMF/trunk/CMFCore/DirectoryView.py
  U   CMF/trunk/CMFCore/FSMetadata.py
  U   CMF/trunk/CMFCore/FSZSQLMethod.py
  U   CMF/trunk/CMFCore/MembershipTool.py
  U   CMF/trunk/CMFCore/Skinnable.py
  U   CMF/trunk/CMFCore/TypesTool.py
  U   CMF/trunk/CMFCore/tests/base/testcase.py
  U   CMF/trunk/CMFCore/tests/test_CMFCatalogAware.py
  U   CMF/trunk/CMFCore/tests/test_FSSecurity.py
  U   CMF/trunk/CMFUid/UniqueIdHandlerTool.py

-=-
Modified: CMF/trunk/CMFCore/CMFCatalogAware.py
===================================================================
--- CMF/trunk/CMFCore/CMFCatalogAware.py	2006-06-08 16:54:49 UTC (rev 68524)
+++ CMF/trunk/CMFCore/CMFCatalogAware.py	2006-06-08 16:55:12 UTC (rev 68525)
@@ -40,6 +40,9 @@
         import ICallableOpaqueItem as z2ICallableOpaqueItem
 
 
+logger = logging.getLogger('CMFCore.CMFCatalogAware')
+
+
 class CMFCatalogAware(Base):
 
     """Mix-in for notifying portal_catalog and portal_workflow
@@ -125,8 +128,8 @@
                 # BBB: Ignore old references to deleted objects.
                 # Can happen only when using
                 # catalog-getObject-raises off in Zope 2.8
-                logging.warn('reindexObjectSecurity',
-                    "Cannot get %s from catalog" % brain_path)
+                logger.warning("reindexObjectSecurity: Cannot get %s from "
+                               "catalog", brain_path)
                 continue
             # Recatalog with the same catalog uid.
             s = getattr(ob, '_p_changed', 0)

Modified: CMF/trunk/CMFCore/DirectoryView.py
===================================================================
--- CMF/trunk/CMFCore/DirectoryView.py	2006-06-08 16:54:49 UTC (rev 68524)
+++ CMF/trunk/CMFCore/DirectoryView.py	2006-06-08 16:55:12 UTC (rev 68525)
@@ -15,10 +15,11 @@
 $Id$
 """
 
-import logging
 import re
 from os import path, listdir, stat
 from sys import platform
+import logging
+from warnings import warn
 
 from AccessControl import ClassSecurityInfo
 from Acquisition import aq_inner, aq_parent
@@ -42,6 +43,9 @@
 from utils import normalize
 
 
+logger = logging.getLogger('CMFCore.DirectoryView')
+
+
 __reload_module__ = 0
 
 # Ignore filesystem artifacts
@@ -140,8 +144,7 @@
                     path.walk(self._filepath, self._walker, filelist)
                     filelist.sort()
             except:
-                logging.exception('DirectoryView',
-                    'Error checking for directory modification')
+                logger.exception("Error checking for directory modification")
 
             if mtime != self._v_last_read or filelist != self._v_last_filelist:
                 self._v_last_read = mtime
@@ -163,8 +166,7 @@
                 self.data, self.objects = self.prepareContents(registry,
                     register_subdirs=changed)
             except:
-                logging.exception('DirectoryView',
-                    'Error during prepareContents:')
+                logger.exception("Error during prepareContents")
                 self.data = {}
                 self.objects = ()
 
@@ -244,7 +246,7 @@
                         import traceback
                         typ, val, tb = sys.exc_info()
                         try:
-                            logging.exception( 'DirectoryView')
+                            logger.exception("prepareContents")
 
                             exc_lines = traceback.format_exception( typ,
                                                                     val,
@@ -264,16 +266,14 @@
                             try:
                                 ob.manage_permission(name,roles,acquire)
                             except ValueError:
-                                logging.exception('DirectoryView',
-                                    'Error setting permissions')
+                                logger.exception("Error setting permissions")
 
                     # only DTML Methods and Python Scripts can have proxy roles
                     if hasattr(ob, '_proxy_roles'):
                         try:
                             ob._proxy_roles = tuple(metadata.getProxyRoles())
                         except:
-                            logging.exception('DirectoryView',
-                                'Error setting proxy role')
+                            logger.exception("Error setting proxy role")
 
                     ob_id = ob.getId()
                     data[ob_id] = ob
@@ -422,7 +422,6 @@
                 # update the directory view with a corrected path
                 self._dirpath = dirpath
             elif self._dirpath:
-                from warnings import warn
                 warn('DirectoryView %s refers to a non-existing path %s'
                      % (self.id, dirpath), UserWarning)
         if info is None:

Modified: CMF/trunk/CMFCore/FSMetadata.py
===================================================================
--- CMF/trunk/CMFCore/FSMetadata.py	2006-06-08 16:54:49 UTC (rev 68524)
+++ CMF/trunk/CMFCore/FSMetadata.py	2006-06-08 16:55:12 UTC (rev 68525)
@@ -15,12 +15,17 @@
 $Id$
 """
 
+import logging
 from os.path import exists
 from ConfigParser import ConfigParser
 from warnings import warn
 
 import re
 
+
+logger = logging.getLogger('CMFCore.FSMetadata')
+
+
 class CMFConfigParser(ConfigParser):
     """ This our wrapper around ConfigParser to
     solve a few minor niggles with the code """
@@ -88,8 +93,7 @@
             self._security = self._getSectionDict(cfg, 'security',
                                                   self._securityParser)
         except:
-            logging.exception('FSMetadata',
-                              'Error parsing .metadata file')
+            logger.exception("Error parsing .metadata file")
 
         # to add in a new value such as proxy roles,
         # just add in the section, call it using getSectionDict
@@ -165,8 +169,7 @@
                 if len(kv) == 2:
                     props[kv[0].strip()] = kv[1].strip()
                 else:
-                    logging.exception('FSMetadata',
-                                      'Error parsing .properties file')
+                    logger.exception("Error parsing .properties file")
 
             return props
 
@@ -201,7 +204,7 @@
                         if role:
                             roles.append(role)
                 except:
-                    logging.exception('DirectoryView',
-                        'Error reading permission from .security file')
+                    logger.exception("Error reading permission "
+                                     "from .security file")
                 prm[permission]=(acquire,roles)
             return prm

Modified: CMF/trunk/CMFCore/FSZSQLMethod.py
===================================================================
--- CMF/trunk/CMFCore/FSZSQLMethod.py	2006-06-08 16:54:49 UTC (rev 68524)
+++ CMF/trunk/CMFCore/FSZSQLMethod.py	2006-06-08 16:55:12 UTC (rev 68525)
@@ -30,6 +30,9 @@
 from utils import expandpath
 
 
+logger = logging.getLogger('CMFCore.FSZSQLMethod')
+
+
 class FSZSQLMethod(SQL, FSObject):
     """FSZSQLMethods act like Z SQL Methods but are not directly
     modifiable from the management interface."""
@@ -141,8 +144,7 @@
                 self._updateFromFS()
                 return self
             except:
-                logging.exception('FS Z SQL Method',
-                                  'Error during __of__')
+                logger.exception("Error during __of__")
                 raise
 
 Globals.InitializeClass(FSZSQLMethod)

Modified: CMF/trunk/CMFCore/MembershipTool.py
===================================================================
--- CMF/trunk/CMFCore/MembershipTool.py	2006-06-08 16:54:49 UTC (rev 68524)
+++ CMF/trunk/CMFCore/MembershipTool.py	2006-06-08 16:55:12 UTC (rev 68525)
@@ -49,6 +49,9 @@
 from utils import UniqueObject
 
 
+logger = logging.getLogger('CMFCore.MembershipTool')
+
+
 class MembershipTool(UniqueObject, Folder, ActionProviderBase):
 
     """ This tool accesses member data through an acl_users object.
@@ -145,8 +148,7 @@
             except ConflictError:
                 raise
             except:
-                logging.exception('CMFCore.MembershipTool',
-                                  'Error during wrapUser')
+                logger.exception("Error during wrapUser")
         return u
 
     security.declareProtected(ManagePortal, 'getPortalRoles')

Modified: CMF/trunk/CMFCore/Skinnable.py
===================================================================
--- CMF/trunk/CMFCore/Skinnable.py	2006-06-08 16:54:49 UTC (rev 68524)
+++ CMF/trunk/CMFCore/Skinnable.py	2006-06-08 16:55:12 UTC (rev 68525)
@@ -29,6 +29,9 @@
 from ZODB.POSException import ConflictError
 
 
+logger = logging.getLogger('CMFCore.Skinnable')
+
+
 # superGetAttr is assigned to whatever ObjectManager.__getattr__
 # used to do.
 try:
@@ -191,7 +194,7 @@
         except:
             # This shouldn't happen, even if the requested skin
             # does not exist.
-            logging.exception('CMFCore', 'Unable to setupCurrentSkin()')
+            logger.exception("Unable to setupCurrentSkin()")
         return w_self
 
     def _checkId(self, id, allow_dup=0):

Modified: CMF/trunk/CMFCore/TypesTool.py
===================================================================
--- CMF/trunk/CMFCore/TypesTool.py	2006-06-08 16:54:49 UTC (rev 68524)
+++ CMF/trunk/CMFCore/TypesTool.py	2006-06-08 16:55:12 UTC (rev 68525)
@@ -54,6 +54,9 @@
 from utils import UniqueObject
 
 
+logger = logging.getLogger('CMFCore.TypesTool')
+
+
 _marker = []  # Create a new marker.
 
 
@@ -387,8 +390,7 @@
         try:
             p = dispatcher[self.product]
         except AttributeError:
-            logging.exception('Types Tool',
-                              '_queryFactoryMethod raised an exception')
+            logger.exception("_queryFactoryMethod raised an exception")
             return default
 
         m = getattr(p, self.factory, None)

Modified: CMF/trunk/CMFCore/tests/base/testcase.py
===================================================================
--- CMF/trunk/CMFCore/tests/base/testcase.py	2006-06-08 16:54:49 UTC (rev 68524)
+++ CMF/trunk/CMFCore/tests/base/testcase.py	2006-06-08 16:55:12 UTC (rev 68525)
@@ -1,9 +1,9 @@
 import unittest
 from Testing import ZopeTestCase
 
-import logging
 import sys
 import time
+import logging
 from os import chmod, curdir, mkdir, remove, stat, walk
 from os.path import join, abspath, dirname
 from shutil import copytree, rmtree
@@ -77,16 +77,16 @@
 class LogInterceptor:
 
     logged = None
-    installed = False
+    installed = ()
     level = 0
 
-    def _catch_log_errors( self, ignored_level=logging.WARNING ):
+    def _catch_log_errors(self, ignored_level=logging.WARNING, subsystem=''):
 
-        if self.installed:
+        if subsystem in self.installed:
             raise ValueError, 'Already installed filter!'
 
-        root_logger = logging.getLogger('')
-        self.installed = True
+        root_logger = logging.getLogger(subsystem)
+        self.installed += (subsystem,)
         self.level = ignored_level
         root_logger.addFilter(self)
 
@@ -98,14 +98,14 @@
         self.logged.append(record)
         return False
 
-    def _ignore_log_errors( self ):
+    def _ignore_log_errors(self, subsystem=''):
 
-        if not self.installed:
+        if subsystem not in self.installed:
             return
 
-        root_logger = logging.getLogger('')
+        root_logger = logging.getLogger(subsystem)
         root_logger.removeFilter(self)
-        self.installed = False
+        self.installed = tuple([s for s in self.installed if s != subsystem])
 
 
 class WarningInterceptor:

Modified: CMF/trunk/CMFCore/tests/test_CMFCatalogAware.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_CMFCatalogAware.py	2006-06-08 16:54:49 UTC (rev 68524)
+++ CMF/trunk/CMFCore/tests/test_CMFCatalogAware.py	2006-06-08 16:55:12 UTC (rev 68525)
@@ -126,6 +126,7 @@
 
     def tearDown(self):
         self._ignore_log_errors()
+        self._ignore_log_errors(subsystem='CMFCore.CMFCatalogAware')
 
     def test_indexObject(self):
         foo = self.site.foo
@@ -189,16 +190,13 @@
 
     def test_reindexObjectSecurity_missing_noraise(self):
         # Raising disabled
+        self._catch_log_errors(subsystem='CMFCore.CMFCatalogAware')
         foo = self.site.foo
         missing = TheClass('missing').__of__(foo)
         missing.GETOBJECT_RAISES = False
         cat = self.site.portal_catalog
-        try:
-            self._catch_log_errors()
-            cat.setObs([foo, missing])
-            foo.reindexObjectSecurity()
-        finally:
-            self._ignore_log_errors()
+        cat.setObs([foo, missing])
+        foo.reindexObjectSecurity()
         self.assertEquals(cat.log,
                           ["reindex /site/foo %s"%str(CMF_SECURITY_INDEXES)])
         self.failIf(foo.notified)

Modified: CMF/trunk/CMFCore/tests/test_FSSecurity.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_FSSecurity.py	2006-06-08 16:54:49 UTC (rev 68524)
+++ CMF/trunk/CMFCore/tests/test_FSSecurity.py	2006-06-08 16:55:12 UTC (rev 68525)
@@ -68,6 +68,7 @@
         RequestTest.tearDown(self)
         WritableFSDVTest.tearDown(self)
         self._ignore_log_errors()
+        self._ignore_log_errors(subsystem='CMFCore.DirectoryView')
 
 
 class FSSecurityTests( FSSecurityBase, LogInterceptor ):
@@ -82,7 +83,7 @@
 
     def test_invalidPermissionNames( self ):
         import logging
-        self._catch_log_errors(logging.ERROR)
+        self._catch_log_errors(logging.ERROR,subsystem='CMFCore.DirectoryView')
         # Test for an invalid permission name
         # baseline
         self._checkSettings(self.ob.fake_skin.test5,'View',1,[])

Modified: CMF/trunk/CMFUid/UniqueIdHandlerTool.py
===================================================================
--- CMF/trunk/CMFUid/UniqueIdHandlerTool.py	2006-06-08 16:54:49 UTC (rev 68524)
+++ CMF/trunk/CMFUid/UniqueIdHandlerTool.py	2006-06-08 16:55:12 UTC (rev 68525)
@@ -191,9 +191,8 @@
         # print a message to the log  if more than one object has
         # the same uid (uups!)
         if len_result > 1:
-            logging.info("CMUid ASSERT:",
-                     "Uups, %s objects have '%s' as uid!!!" % \
-                     (len_result, uid))
+            logging.getLogger('CMFUid').error(
+                "ASSERT: %d objects have %r as uid!!!", len_result, uid)
 
         return result[0]
 



More information about the CMF-checkins mailing list