[Zope] They mysteries of logging in zope.

John Morton John Morton <jwm@plain.co.nz>
Thu, 8 Mar 2001 14:35:39 +1300 (NZDT)


On Thu, 8 Mar 2001 13:42:59 +1300 (NZDT) John Morton <jwm@plain.co.nz> wrot=
e:

> 2. ZServer and ZLogger both use a copy each of Sam Rushing's syslog
> module, but while ZLogger calls it properly, ZServer simply isn't. It
> doesn't appear to pass it a port at all.
>=20
> 3. Further up the line, the code that creates the logging object seems to
> pass ZSYSLOG straight through as a server address.

Actually this analysis is completely wrong, as it turns out. This is
what's really going on:

For the ZSYSLOG case, the documentation claims that the environment
variable can be set to anything, and it will log to /dev/log:

http://www.zope.org/Documentation/Misc/LOGGING.txt

This is true in the case of ZLogger, but ZServer passes the value to
syslog_client which treats string addresses as filesystem sockets to write
to - so ZSYSLOG better be set to /dev/log or ZServer will bomb on startup.

Patching lib/python/ZLogger/syslogLogger.py like this:


--- syslogLogger-old.py=09Thu Mar  8 14:22:32 2001
+++ syslogLogger.py=09Thu Mar  8 14:22:56 2001
@@ -99,7 +99,7 @@
             self.client =3D syslog_client((addr, int(port)))
             self.on =3D 1
         elif os.environ.has_key('ZSYSLOG'):
-            self.client =3D syslog_client()
+            self.client =3D syslog_client(os.environ['ZSYSLOG'])
             self.on =3D 1
         else:
             self.on =3D 0

...will mean that ZLogger uses the same behaviour as ZServer

For the ZSYSLOG_SERVER case, ZLogger is doing the right thing by turning
the string address into an address, port tuple. This is also performed in
z2.py, but the code there doesn't make sure that the port number is an
integer, causing an eventual type error.

--- z2-old.py=09Thu Mar  8 14:25:08 2001
+++ z2.py=09Thu Mar  8 14:25:56 2001
@@ -594,7 +594,8 @@
 elif os.environ.has_key('ZSYSLOG'):
     lg =3D logger.syslog_logger(os.environ['ZSYSLOG'])
 elif os.environ.has_key('ZSYSLOG_SERVER'):
-    lg =3D logger.syslog_logger(string.split(os.environ['ZSYSLOG_SERVER'],
':'))
+    (address, port) =3D string.split(os.environ['ZSYSLOG_SERVER'], ':')
+    lg =3D logger.syslog_logger((address, int(port)))
 else:
     lg =3D logger.file_logger(LOG_PATH)

(I've submitted it all to the collector, BTW).

John