[Zodb-checkins] CVS: ZODB3/zdaemon - zdoptions.py:1.6

Guido van Rossum guido@python.org
Fri, 17 Jan 2003 15:18:41 -0500


Update of /cvs-repository/ZODB3/zdaemon
In directory cvs.zope.org:/tmp/cvs-serv13082

Modified Files:
	zdoptions.py 
Log Message:
Add support for automatic processing of a <logger> section.  This is
enabled by setting the class variable 'logsectionname'.


=== ZODB3/zdaemon/zdoptions.py 1.5 => 1.6 ===
--- ZODB3/zdaemon/zdoptions.py:1.5	Fri Jan 17 13:11:41 2003
+++ ZODB3/zdaemon/zdoptions.py	Fri Jan 17 15:18:38 2003
@@ -16,6 +16,11 @@
     schema = None
     configroot = None
 
+    # Class variable to control automatic processing of a <logger>
+    # section.  This should be the (possibly dotted) name of something
+    # accessible from configroot, typically "logger".
+    logsectionname = None
+
     # Class variable deciding whether positional arguments are allowed.
     # If you want positional arguments, set this to 1 in your subclass.
     positional_args_allowed = 0
@@ -242,6 +247,30 @@
         for name, message in self.required_map.items():
             if getattr(self, name) is None:
                 self.usage(message)
+
+        if self.logsectionname:
+            self.load_logconf(self.logsectionname)
+
+    def load_logconf(self, sectname="logger"):
+        parts = sectname.split(".")
+        obj = self.configroot
+        for p in parts:
+            if obj == None:
+                break
+            obj = getattr(obj, p)
+        self.config_logger = obj
+        if obj is not None:
+            import zLOG
+            zLOG.set_initializer(self.log_initializer)
+            zLOG.initialize()
+
+    def log_initializer(self):
+        from zLOG import EventLogger
+        logger = self.config_logger()
+        for handler in logger.handlers:
+            if hasattr(handler, "reopen"):
+                handler.reopen()
+        EventLogger.event_logger.logger = logger
 
 
 def _test():