[Zodb-checkins] CVS: ZODB3/zLOG - component.xml:1.2 datatypes.py:1.3

Fred L. Drake, Jr. fred@zope.com
Thu, 16 Jan 2003 10:36:31 -0500


Update of /cvs-repository/ZODB3/zLOG
In directory cvs.zope.org:/tmp/cvs-serv6543/zLOG

Modified Files:
	component.xml datatypes.py 
Log Message:
- move the datatype for logging levels into the zLOG schema component
- add at least something of a test for the datatype


=== ZODB3/zLOG/component.xml 1.1 => 1.2 ===
--- ZODB3/zLOG/component.xml:1.1	Fri Jan 10 13:33:08 2003
+++ ZODB3/zLOG/component.xml	Thu Jan 16 10:35:57 2003
@@ -8,7 +8,7 @@
     <key name="format" default="------\n%(asctime)s %(message)s"
          datatype=".log_format"/>
     <key name="dateformat" default="%Y-%m-%dT%H:%M:%S"/>
-    <key name="level" default="info" datatype="logging-level"/>
+    <key name="level" default="info" datatype=".logging_level"/>
   </sectiontype>
 
   <sectiontype name="syslog-handler" datatype=".syslog_handler"
@@ -18,7 +18,7 @@
     <key name="format" default="%(message)s"
          datatype=".log_format"/>
     <key name="dateformat" default="%Y-%m-%dT%H:%M:%S"/>
-    <key name="level" default="info" datatype="logging-level"/>
+    <key name="level" default="info" datatype=".logging_level"/>
   </sectiontype>
 
 <!--
@@ -28,7 +28,7 @@
     <key name="format" default="%(message)s"
          datatype=".log_format"/>
     <key name="dateformat" default="%Y-%m-%dT%H:%M:%S"/>
-    <key name="level" default="info" datatype="logging-level"/>
+    <key name="level" default="info" datatype=".logging_level"/>
   </sectiontype>
 
   <sectiontype name="http_handler" datatype=".http_handler"
@@ -38,7 +38,7 @@
     <key name="format" default="%(asctime)s %(message)s"
          datatype=".log_format"/>
     <key name="dateformat" default="%Y-%m-%dT%H:%M:%S"/>
-    <key name="level" default="info" datatype="logging-level"/>
+    <key name="level" default="info" datatype=".logging_level"/>
   </sectiontype>
 
   <sectiontype name="smtp_handler" datatype=".smtp_handler"
@@ -50,7 +50,7 @@
     <key name="format" default="%(asctime)s %(message)s"
          datatype=".log_format"/>
     <key name="dateformat" default="%Y-%m-%dT%H:%M:%S"/>
-    <key name="level" default="info" datatype="logging-level"/>
+    <key name="level" default="info" datatype=".logging_level"/>
   </sectiontype>
 
   <sectiontype name="null_handler" datatype=".null_handler"
@@ -61,12 +61,12 @@
     <key name="constructor" datatype="constructor" required="yes"/>
     <key name="formatter" datatype="constructor"
          default="logging.Formatter()"/>
-    <key name="level" default="info" datatype="logging-level"/>
+    <key name="level" default="info" datatype=".logging_level"/>
   </sectiontype>
 -->
 
   <sectiontype name="logger" datatype=".logger">
-     <key name="level" datatype="logging-level" default="info"/>
+     <key name="level" datatype=".logging_level" default="info"/>
      <multisection type="loghandler" attribute="handlers" name="*"/>
   </sectiontype>
 


=== ZODB3/zLOG/datatypes.py 1.2 => 1.3 ===
--- ZODB3/zLOG/datatypes.py:1.2	Mon Jan 13 11:16:42 2003
+++ ZODB3/zLOG/datatypes.py	Thu Jan 16 10:35:57 2003
@@ -20,6 +20,26 @@
 
 # log-related datatypes
 
+_logging_levels = {
+    "critical": 50,
+    "fatal": 50,
+    "error": 40,
+    "warn": 30,
+    "info": 20,
+    "debug": 10,
+    "all": 0,
+    }
+
+def logging_level(value):
+    s = str(value).lower()
+    if _logging_levels.has_key(s):
+        return _logging_levels[s]
+    else:
+        v = int(s)
+        if v < 0 or v > 50:
+            raise ValueError("log level not in range: " + `v`)
+        return v
+
 _log_format_variables = {
     'name': '',
     'levelno': '3',