[Zodb-checkins] CVS: Zope/lib/python/zLOG - EventLogger.py:1.1.2.5

Chris McDonough chrism@zope.com
Mon, 25 Nov 2002 02:41:58 -0500


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

Modified Files:
      Tag: chrism-install-branch
	EventLogger.py 
Log Message:
Changes to support new schema regime.


=== Zope/lib/python/zLOG/EventLogger.py 1.1.2.4 => 1.1.2.5 ===
--- Zope/lib/python/zLOG/EventLogger.py:1.1.2.4	Sun Nov 24 19:19:52 2002
+++ Zope/lib/python/zLOG/EventLogger.py	Mon Nov 25 02:41:56 2002
@@ -29,9 +29,20 @@
 from LogHandlers import FileHandler, NullHandler, SysLogHandler
 from logging import StreamHandler, Formatter
 
+def get_formatter(type):
+    formatters =  {
+    'file':    Formatter(fmt='------\n%(asctime)s %(message)s',
+                         datefmt='%Y-%m-%dT%H:%M:%S'),
+    'syslog':  Formatter(fmt='%(message)s'),
+    }
+    return formatters[type]
+
 class EventLogger(BaseLogger):
     logger = logging.getLogger('event')
-    logger.addHandler(NullHandler())
+    handler = NullHandler()
+    handler.setFormatter(get_formatter('file'))
+    logger.addHandler(handler)
+    
     log_format = '%(sev)s %(subsys)s %(summary)s%(detail)s'
     
     def log(self, subsystem, severity, summary, detail, error):
@@ -146,12 +157,6 @@
         dest = path
     return dest
 
-formatters = {
-    'file':    Formatter(fmt='------\n%(asctime)s %(message)s',
-                         datefmt='%Y-%m-%dT%H:%M:%S'),
-    'syslog':  Formatter(fmt='%(message)s'),
-    }
-
 def initialize_from_environment():
     """ Reinitialize the event logger from the environment """
     # clear the current handlers from the event logger
@@ -163,19 +168,19 @@
     facility, syslogdest = get_env_syslog_info()
     if syslogdest:
         handler = SysLogHandler(syslogdest, facility)
-        handler.setFormatter(formatters['syslog'])
+        handler.setFormatter(get_formatter('syslog'))
         handlers.append(handler)
 
     # set up file handler if necessary
     filedest = get_env_file_info()
     if filedest:
         handler = FileHandler(filedest)
-        handler.setFormatter(formatters['file'])
+        handler.setFormatter(get_formatter('file'))
         handlers.append(handler)
     elif filedest == '':
         # if dest is an empty string, log to standard error
         handler = StreamHandler()
-        handler.setFormatter(formatters['file'])
+        handler.setFormatter(get_formatter('file'))
         handlers.append(handler)
     else:
         # log to nowhere, but install a 'null' handler in order to