[Zodb-checkins] CVS: Zope/lib/python/zLOG/tests - testzLog.py:1.10

Fred L. Drake, Jr. fred@zope.com
Thu, 21 Nov 2002 18:17:58 -0500


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

Modified Files:
	testzLog.py 
Log Message:
- zLOG.severity():  Convenience function that converts a value to a
  severity level.  This allows the common names to be used for
  severities, not just integers.  This can make configuration data
  less obscure.

- Refactor initialize():
  get_environment_info() pulls information from the environment
  variables, and this gets passed to initialize_log(), which does
  nothing to determine the source of the configuration data.

- New method initialize_with_config():  Load information not provided
  by the environment from a ZConfig section.  This allows the
  environment to override a config file, and avoids having the
  application deal with the specific information needed to configure
  logging.


=== Zope/lib/python/zLOG/tests/testzLog.py 1.9 => 1.10 ===
--- Zope/lib/python/zLOG/tests/testzLog.py:1.9	Fri Aug 16 16:31:33 2002
+++ Zope/lib/python/zLOG/tests/testzLog.py	Thu Nov 21 18:17:57 2002
@@ -8,7 +8,7 @@
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE
+# FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
 
@@ -16,6 +16,10 @@
 import sys
 import tempfile
 import unittest
+
+from cStringIO import StringIO
+
+import ZConfig
 import zLOG
 
 severity_string = {
@@ -60,7 +64,7 @@
 
     def setLog(self, severity=0):
         os.environ['%s_LOG_FILE' % self.prefix] = self.path
-        if severity:
+        if severity is not None:
             os.environ['%s_LOG_SEVERITY' % self.prefix] = str(severity)
         self._severity = severity
         zLOG.MinimalLogger._log.initialize()
@@ -107,13 +111,19 @@
     def getLogFile(self):
         return open(self.path, 'rb')
 
-    def checkBasics(self):
-        self.setLog()
+    def checkBasics(self, severity=None):
+        self.setLog(severity=severity)
         zLOG.LOG("basic", zLOG.INFO, "summary")
 
         f = self.getLogFile()
         self.verifyEntry(f, subsys="basic", summary="summary")
 
+    def checkBasicsNumericSeverity(self):
+        self.checkBasics(severity=0)
+
+    def checkBasicsNamedSeverity(self):
+        self.checkBasics(severity='info')
+
     def checkDetail(self):
         self.setLog()
         zLOG.LOG("basic", zLOG.INFO, "xxx", "this is a detail")
@@ -140,9 +150,24 @@
     """ Test alternate envvars EVENT_LOG_FILE and EVENT_LOG_SEVERITY """
     prefix = 'EVENT'
 
+class ConfigLogTest(StupidLogTest):
+    """ Test using a ZConfig section to control logging. """
+
+    def setLog(self, severity=None):
+        self._severity = severity
+        text = "<Log>\n path %s \n" % self.path
+        if severity is not None:
+            text += "  level %s \n" % severity
+        text += "</Log>"
+        sio = StringIO(text)
+        conf = ZConfig.loadfile(sio)
+        zLOG.MinimalLogger._log.initialize_with_config(conf)
+
+
 def test_suite():
     suite = unittest.makeSuite(StupidLogTest, 'check')
     suite.addTest(unittest.makeSuite(EventLogTest, 'check'))
+    suite.addTest(unittest.makeSuite(ConfigLogTest, 'check'))
     return suite
 
 if __name__ == "__main__":