Commit bb1baafd authored by Fred Drake's avatar Fred Drake

- move the datatype for logging levels into the zLOG schema component

- add at least something of a test for the datatype
parent 4db19034
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<key name="format" default="------\n%(asctime)s %(message)s" <key name="format" default="------\n%(asctime)s %(message)s"
datatype=".log_format"/> datatype=".log_format"/>
<key name="dateformat" default="%Y-%m-%dT%H:%M:%S"/> <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>
<sectiontype name="syslog-handler" datatype=".syslog_handler" <sectiontype name="syslog-handler" datatype=".syslog_handler"
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<key name="format" default="%(message)s" <key name="format" default="%(message)s"
datatype=".log_format"/> datatype=".log_format"/>
<key name="dateformat" default="%Y-%m-%dT%H:%M:%S"/> <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>
<!-- <!--
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
<key name="format" default="%(message)s" <key name="format" default="%(message)s"
datatype=".log_format"/> datatype=".log_format"/>
<key name="dateformat" default="%Y-%m-%dT%H:%M:%S"/> <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>
<sectiontype name="http_handler" datatype=".http_handler" <sectiontype name="http_handler" datatype=".http_handler"
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<key name="format" default="%(asctime)s %(message)s" <key name="format" default="%(asctime)s %(message)s"
datatype=".log_format"/> datatype=".log_format"/>
<key name="dateformat" default="%Y-%m-%dT%H:%M:%S"/> <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>
<sectiontype name="smtp_handler" datatype=".smtp_handler" <sectiontype name="smtp_handler" datatype=".smtp_handler"
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
<key name="format" default="%(asctime)s %(message)s" <key name="format" default="%(asctime)s %(message)s"
datatype=".log_format"/> datatype=".log_format"/>
<key name="dateformat" default="%Y-%m-%dT%H:%M:%S"/> <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>
<sectiontype name="null_handler" datatype=".null_handler" <sectiontype name="null_handler" datatype=".null_handler"
...@@ -61,12 +61,12 @@ ...@@ -61,12 +61,12 @@
<key name="constructor" datatype="constructor" required="yes"/> <key name="constructor" datatype="constructor" required="yes"/>
<key name="formatter" datatype="constructor" <key name="formatter" datatype="constructor"
default="logging.Formatter()"/> default="logging.Formatter()"/>
<key name="level" default="info" datatype="logging-level"/> <key name="level" default="info" datatype=".logging_level"/>
</sectiontype> </sectiontype>
--> -->
<sectiontype name="logger" datatype=".logger"> <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="*"/> <multisection type="loghandler" attribute="handlers" name="*"/>
</sectiontype> </sectiontype>
......
...@@ -20,6 +20,26 @@ from zLOG.factory import Factory ...@@ -20,6 +20,26 @@ from zLOG.factory import Factory
# log-related datatypes # 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 = { _log_format_variables = {
'name': '', 'name': '',
'levelno': '3', 'levelno': '3',
......
...@@ -19,6 +19,7 @@ import logging ...@@ -19,6 +19,7 @@ import logging
import unittest import unittest
import ZConfig import ZConfig
import zLOG.datatypes
import zLOG.LogHandlers import zLOG.LogHandlers
import zLOG.tests import zLOG.tests
...@@ -45,6 +46,19 @@ class TestzLOGConfig(unittest.TestCase): ...@@ -45,6 +46,19 @@ class TestzLOGConfig(unittest.TestCase):
self.assert_(not handler) self.assert_(not handler)
return conf return conf
def test_logging_level(self):
# Make sure the expected names are supported; it's not clear
# how to check the values in a meaningful way.
convert = zLOG.datatypes.logging_level
convert("all")
convert("debug")
convert("info")
convert("warn")
convert("error")
convert("fatal")
convert("critical")
self.assertRaises(ValueError, convert, "hopefully-not-a-valid-value")
def test_config_without_logger(self): def test_config_without_logger(self):
conf = self.get_config("") conf = self.get_config("")
self.assert_(conf.logger is None) self.assert_(conf.logger is None)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment