[Zodb-checkins] CVS: Zope/lib/python/zLOG - datatypes.py:1.10.18.1

Jim Fulton cvs-admin at zope.org
Sat Nov 15 07:11:48 EST 2003


Update of /cvs-repository/Zope/lib/python/zLOG
In directory cvs.zope.org:/tmp/cvs-serv25037/lib/python/zLOG

Modified Files:
      Tag: zodb33-devel-branch
	datatypes.py 
Log Message:
Copied code forward from trunk that was missed when the branch was created.


=== Zope/lib/python/zLOG/datatypes.py 1.10 => 1.10.18.1 ===
--- Zope/lib/python/zLOG/datatypes.py:1.10	Thu Jan 23 16:38:03 2003
+++ Zope/lib/python/zLOG/datatypes.py	Sat Nov 15 07:11:45 2003
@@ -97,6 +97,9 @@
         logger.setLevel(self.section.level)
         return logger
 
+    def getLevel(self):
+        return self.section.level
+
 class FileHandlerFactory(HandlerFactory):
     def create_loghandler(self):
         from zLOG.LogHandlers import StreamHandler, FileHandler
@@ -224,3 +227,61 @@
             from zLOG.LogHandlers import NullHandler
             logger.addHandler(NullHandler())
         return logger
+
+    def getLowestHandlerLevel(self):
+        """ Return the lowest log level provided by any of our handlers
+        (used by Zope startup logger code to decide what to send
+        to stderr during startup) """
+        lowest = self.level
+        for factory in self.handler_factories:
+            handler_level = factory.getLevel()
+            if handler_level < lowest:
+                lowest = factory.getLevel()
+        return lowest
+
+def importable_name(name):
+    try:
+        components = name.split('.')
+        start = components[0]
+        g = globals()
+        package = __import__(start, g, g)
+        modulenames = [start]
+        for component in components[1:]:
+            modulenames.append(component)
+            try:
+                package = getattr(package, component)
+            except AttributeError:
+                n = '.'.join(modulenames)
+                package = __import__(n, g, g, component)
+        return package
+    except ImportError:
+        raise ValueError, (
+            'The object named by "%s" could not be imported' %  name )
+
+def warning_subclass(val):
+    ob = importable_name(val) # will fail in course
+    try:
+        if not issubclass(ob, Warning):
+            raise ValueError, (
+                'warning category "%s" must be a Warning subclass' % val)
+    except TypeError:
+            raise ValueError, (
+                'warning category "%s" must be a Warning subclass' % val)
+        
+    return ob
+
+def warn_action(val):
+    OK = ("error", "ignore", "always", "default", "module", "once")
+    if val not in OK:
+        raise ValueError, "warning action %s not one of %s" % (val, OK)
+    return val
+
+def warning_filter_handler(section):
+    import warnings
+    # add the warning filter
+    warnings.filterwarnings(section.action, section.message, section.category,
+                            section.module, section.lineno, 1)
+    return section
+
+
+




More information about the Zodb-checkins mailing list