quick search:
 

Simple debugging using a STUPID_LOG_FILE and zLog

Submitted by: Ola
Last Edited: 2004-10-14

Category: Python(External Method)

Average rating is: 4.5 out of 5 (2 ratings)

Description:
Easy debugging for Zope. debug your application by puking out lots of data to a file in your log file. This is for Linux/Unix and friends, mind you

Source (Text):
import zLOG

def log(message,summary='',severity=0):
        zLOG.LOG('MyDebugLog',severity,summary,message)

Explanation:
Steps:
% export STUPID_LOG_FILE=/tmp/stupid_log_file
% zopectl stop
% zopectl start
(a simple zopectl restart won't work)
% tail -f $STUPID_LOG_FILE

In Zope: add your log.py as an external method (duh) named something like 'log'

Debuglogging from DTML:
<dtml-call expr="log('Kilroy logged this')">

Debuglogging from any old Script (Python):

context.log('Kilroy did yer girlfriend over')

Not much to it


Comments:

By the way, zLog is also the debug log you invoke by the -D switch by Holger Blasum - 2004-10-14
So optimizing '/etc/init.d/zope' for simplicity (not necessarily robustness) gives::

#!/bin/sh
ZOPE_HOME=/usr/lib/zope
export INSTANCE_HOME=/var/lib/zope

#zLog, works like apache error log (registering errors and
#restarts). You can also use it for debugging your apps: see the cookbook
#at http://www.zopelabs.com/cookbook/1002053681 .
zope_error=/var/log/zope_error

#ZServer log, logs access like the apache access log.
zope_access=/var/log/zope_access

zope_pid=$INSTANCE_HOME/var/Z2.pid

case "$1" in
        start)
                /usr/sbin/zope-z2 -l $zope_access -D >>$zope_error \
                2>>$zope_error &
                echo "zope starting"
        ;;
        stop)
                kill `cat $zope_pid` && \
                rm -f $zope_pid && \
                echo "zope stopped"
        ;;
esac