They mysteries of logging in zope.
In the process of building a new login method for the Login Manager product, I thought it would be a good idea to have the beast log various indications of state out to syslog for later examination. ZLogger's interface is nice and easy and it looked like all I had to do to get logging to go to syslog was to set an environment variable. Unfortunately it just doesn't work that easily. Setting ZSYSLOG to log via /dev/log causes zope to crash straight away, setting ZSYSLOG_SERVER causes it to crash after between 10 seconds and a minute, and setting STUPID_FILE_LOGGER does nothing at all. Wading into the code I discovered a few things, and made some other observations: 1. There are no less than three separate logging systems used in Zope - logging via ZServer, logging via ZLogger and some form of debug logging via DebugLogger. They all seem to have different APIs. 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. 3. Further up the line, the code that creates the logging object seems to pass ZSYSLOG straight through as a server address. I expect that a pair of patches to ZServer and z2.py will be able to fix the problem, but I'm interested if anyone has found any other solutions. John
On Thu, 8 Mar 2001 13:42:59 +1300 (NZDT) John Morton <jwm@plain.co.nz> wrote:
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.
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 Thu Mar 8 14:22:32 2001 +++ syslogLogger.py Thu Mar 8 14:22:56 2001 @@ -99,7 +99,7 @@ self.client = syslog_client((addr, int(port))) self.on = 1 elif os.environ.has_key('ZSYSLOG'): - self.client = syslog_client() + self.client = syslog_client(os.environ['ZSYSLOG']) self.on = 1 else: self.on = 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 Thu Mar 8 14:25:08 2001 +++ z2.py Thu Mar 8 14:25:56 2001 @@ -594,7 +594,8 @@ elif os.environ.has_key('ZSYSLOG'): lg = logger.syslog_logger(os.environ['ZSYSLOG']) elif os.environ.has_key('ZSYSLOG_SERVER'): - lg = logger.syslog_logger(string.split(os.environ['ZSYSLOG_SERVER'], ':')) + (address, port) = string.split(os.environ['ZSYSLOG_SERVER'], ':') + lg = logger.syslog_logger((address, int(port))) else: lg = logger.file_logger(LOG_PATH) (I've submitted it all to the collector, BTW). John
participants (1)
-
John Morton