[Zope3-checkins] CVS: Zope3/lib/python/ZEO - runsvr.py:1.3

Guido van Rossum guido@python.org
Thu, 19 Dec 2002 16:35:09 -0500


Update of /cvs-repository/Zope3/lib/python/ZEO
In directory cvs.zope.org:/tmp/cvs-serv3773

Modified Files:
	runsvr.py 
Log Message:
Convert to logging module.


=== Zope3/lib/python/ZEO/runsvr.py 1.2 => 1.3 ===
--- Zope3/lib/python/ZEO/runsvr.py:1.2	Mon Dec 16 16:04:42 2002
+++ Zope3/lib/python/ZEO/runsvr.py	Thu Dec 19 16:35:09 2002
@@ -37,12 +37,9 @@
 import getopt
 import signal
 import socket
-
-import zLOG
+import logging
 
 import ZConfig
-import ZConfig.Common
-import ZConfig.Storage
 
 
 class Options:
@@ -206,7 +203,7 @@
             return
         try:
             self.hostconf = self.rootconf.getSection("Host")
-        except ZConfig.Common.ConfigurationConflictingSectionError:
+        except ZConfig.ConfigurationConflictingSectionError:
             if not self.hostname:
                 self.hostname = socket.getfqdn()
             self.hostconf = self.rootconf.getSection("Host", self.hostname)
@@ -221,7 +218,6 @@
 
         # Now extract options from various configuration sections
         self.load_zeoconf()
-        self.load_logconf()
         self.load_storages()
 
     def load_zeoconf(self):
@@ -243,28 +239,6 @@
             self.family = socket.AF_UNIX
             self.address = path
 
-    def load_logconf(self):
-        # Get logging options from conf, unless overridden by environment
-        if not self.logconf:
-            return
-        reinit = 0
-        if os.getenv("EVENT_LOG_FILE") is None:
-            if os.getenv("STUPID_LOG_FILE") is None:
-                path = self.logconf.get("path")
-                if path is not None:
-                    os.environ["EVENT_LOG_FILE"] = path
-                    os.environ["STUPID_LOG_FILE"] = path
-                    reinit = 1
-        if os.getenv("EVENT_LOG_SEVERITY") is None:
-            if os.getenv("STUPID_LOG_SEVERITY") is None:
-                level = self.logconf.get("level")
-                if level is not None:
-                    os.environ["EVENT_LOG_SEVERITY"] = level
-                    os.environ["STUPID_LOG_SEVERITY"] = level
-                    reinit = 1
-        if reinit:
-            zLOG.initialize()
-
     def load_storages(self):
         # Get the storage specifications
         if self.storages:
@@ -272,6 +246,7 @@
             return
         storagesections = self.zeoconf.getChildSections("Storage")
         self.storages = {}
+        from ZODB.StorageConfig import getStorageInfo
         for section in storagesections:
             name = section.name
             if not name:
@@ -279,7 +254,7 @@
             if self.storages.has_key(name):
                 # (Actually, the parser doesn't allow this)
                 self.usage("duplicate storage name %r" % name)
-            self.storages[name] = ZConfig.Storage.getStorageInfo(section)
+            self.storages[name] = getStorageInfo(section)
 
 
 class ZEOServer:
@@ -328,8 +303,8 @@
     def open_storages(self):
         self.storages = {}
         for name, (cls, args) in self.options.storages.items():
-            info("open storage %r: %s.%s(**%r)" %
-                 (name, cls.__module__, cls.__name__, args))
+            logging.info("open storage %r: %s.%s(**%r)",
+                         name, cls.__module__, cls.__name__, args)
             self.storages[name] = cls(**args)
 
     def setup_signals(self):
@@ -361,28 +336,24 @@
         ThreadedAsync.loop()
 
     def handle_sigterm(self):
-        info("terminated by SIGTERM")
+        logging.info("terminated by SIGTERM")
         sys.exit(0)
 
     def handle_sigint(self):
-        info("terminated by SIGINT")
+        logging.info("terminated by SIGINT")
         sys.exit(0)
 
     def handle_sigusr2(self):
-        # This requires a modern zLOG (from Zope 2.6 or later); older
-        # zLOG packages don't have the initialize() method
-        info("reinitializing zLOG")
-        # XXX Shouldn't this be below with _log()?
-        import zLOG
-        zLOG.initialize()
+        # XXX What to do here?
+        logging.error("Don't know how to reinitialize log files yet")
 
     def close_storages(self):
         for name, storage in self.storages.items():
-            info("closing storage %r" % name)
+            logging.info("closing storage %r", name)
             try:
                 storage.close()
             except: # Keep going
-                exception("failed to close storage %r" % name)
+                logging.exception("failed to close storage %r", name)
 
 
 # Signal names
@@ -411,41 +382,19 @@
             signames[sig] = name
 
 
-# Log messages with various severities.
-# This uses zLOG, but the API is a simplified version of PEP 282
-
-def critical(msg):
-    """Log a critical message."""
-    _log(msg, zLOG.PANIC)
-
-def error(msg):
-    """Log an error message."""
-    _log(msg, zLOG.ERROR)
-
-def exception(msg):
-    """Log an exception (an error message with a traceback attached)."""
-    _log(msg, zLOG.ERROR, error=sys.exc_info())
-
-def warn(msg):
-    """Log a warning message."""
-    _log(msg, zLOG.PROBLEM)
-
-def info(msg):
-    """Log an informational message."""
-    _log(msg, zLOG.INFO)
-
-def debug(msg):
-    """Log a debugging message."""
-    _log(msg, zLOG.DEBUG)
-
-def _log(msg, severity=zLOG.INFO, error=None):
-    """Internal: generic logging function."""
-    zLOG.LOG("RUNSVR", severity, msg, "", error)
-
-
 # Main program
 
 def main(args=None):
+
+    # Initialize the logging module.
+    # XXX This is a temporary hack.
+    import logging.config
+    logging.basicConfig()
+    logging.root.setLevel(logging.CRITICAL)
+    # If log.ini exists, use it
+    if os.path.exists("log.ini"):
+        logging.config.fileConfig("log.ini")
+
     options = ZEOOptions(args)
     s = ZEOServer(options)
     s.main()