Commit 20a948f9 authored by Chris McDonough's avatar Chris McDonough

- The default "start" script now causes the event log to be sent to

        standard output unless the "EVENT_LOG_FILE" or "STUPID_LOG_FILE"
        environment variable is set.

      - The much-hated name "STUPID_LOG_FILE" now has a preferred
        alias:  "EVENT_LOG_FILE".
parent 1070a4cb
...@@ -6,6 +6,13 @@ Zope Changes ...@@ -6,6 +6,13 @@ Zope Changes
Bugs Fixed Bugs Fixed
- The default "start" script now causes the event log to be sent to
standard output unless the "EVENT_LOG_FILE" or "STUPID_LOG_FILE"
environment variable is found in the environment.
- The much-hated name "STUPID_LOG_FILE" now has a preferred
alias: "EVENT_LOG_FILE".
- Collector 454: The "default" session_data transient object - Collector 454: The "default" session_data transient object
container was not created if an object named "session_data" container was not created if an object named "session_data"
existed in the root. existed in the root.
......
...@@ -71,30 +71,31 @@ ZEO ...@@ -71,30 +71,31 @@ ZEO
the client cache is stored in temporary files which are removed the client cache is stored in temporary files which are removed
when the ClientStorage shuts down. when the ClientStorage shuts down.
Debugging and Logging Debugging and Logging
STUPID_LOG_FORMAT EVENT_LOG_FORMAT or STUPID_LOG_FORMAT
Set this variable if you like to customize the output format of Set this variable if you like to customize the output format of
Zope stupid logger. Zope event logger. EVENT_LOG_FORMAT is the preferred envvar
but STUPID_LOG_FORMAT also works.
STUPID_LOG_FILE="path" EVENT_LOG_FILE="path" or STUPID_LOG_FILE="path"
The stupid file logger writes Zope logging information to a file. The event file logger writes Zope logging information to a file.
It is not very smart about it - it just dumps it to a file and the It is not very smart about it - it just dumps it to a file and the
format is not very configurable - hence the name. format is not very configurable - hence the name STUPID_LOG_FILE.
EVENT_LOG_FILE is the preferred envvar but STUPID_LOG_FILE
also works.
See also: LOGGING.txt See also: LOGGING.txt
STUPID_LOG_SEVERITY <number> EVENT_LOG_SEVERITY <number> or STUPID_LOG_SEVERITY <number>
If set, Zope logs only messages whose severity is level
is higher than the specified one.
If set, Zope logs only messages whose severity is level is
higher than the specified one. EVENT_LOG_SEVERITY is the
preferred envvar but STUPID_LOG_SEVERITY also works.
ZSYSLOG="/dev/log" ZSYSLOG="/dev/log"
......
...@@ -11,13 +11,13 @@ Zope Logging ...@@ -11,13 +11,13 @@ Zope Logging
example:: example::
$ python2.1 z2.py ZSYSLOG_SERVER="syslog.mydomain.com:514" \ $ python2.1 z2.py ZSYSLOG_SERVER="syslog.mydomain.com:514" \
STUPID_LOG_FILE="var/Zope.log" EVENT_LOG_FILE="var/Zope.log"
Currently, the following environment variables can be set: Currently, the following environment variables can be set:
STUPID_LOG_FILE="path" EVENT_LOG_FILE="path"
The stupid file logger writes Zope logging information to a file. The event file logger writes Zope logging information to a file.
It is not very smart about it - it just dumps it to a file and the It is not very smart about it - it just dumps it to a file and the
format is not very configurable - hence the name. format is not very configurable - hence the name.
......
...@@ -25,23 +25,37 @@ def sh(home, user, group): ...@@ -25,23 +25,37 @@ def sh(home, user, group):
if not os.path.exists(start): if not os.path.exists(start):
print '-'*78 print '-'*78
print 'Creating start script, start' print 'Creating start script, start'
open(start,'w').write( f = open(start,'w')
"#! /bin/sh\n" f.write(START_SCRIPT % (varname, varname, sys.executable, varname))
"umask 077\n"
"reldir=`dirname $0`\n"
"%s=`cd $reldir; pwd`\n"
"export %s\n"
'exec %s \\\n $%s/z2.py \\\n -D "$@"\n'
% (varname, varname, sys.executable, varname))
ch(start,user,group,0711) ch(start,user,group,0711)
f.close()
stop=os.path.join(home, 'stop') stop=os.path.join(home, 'stop')
if not os.path.exists(stop): if not os.path.exists(stop):
print '-'*78 print '-'*78
print 'Creating stop script, stop' print 'Creating stop script, stop'
open(stop,'w').write( f = open(stop,'w')
"#! /bin/sh\n" f.write(STOP_SCRIPT % os.path.join(home,'var','Z2.pid'))
"kill `cat %s`"
% os.path.join(home,'var','Z2.pid'))
ch(stop,user,group,0711) ch(stop,user,group,0711)
f.close()
START_SCRIPT="""#!/bin/sh
umask 077
reldir=`dirname $0`
# Zope's event logger is controlled by the "EVENT_LOG_FILE" environment
# variable. If you don't have a "EVENT_LOG_FILE" environment variable
# (or its older alias "STUPID_LOG_FILE") set, Zope will log to the standard
# output. For more information on EVENT_LOG_FILE, see doc/ENVIRONMENT.txt.
ZLOGFILE=$EVENT_LOG_FILE
if [ -z "$ZLOGFILE" ]; then
ZLOGFILE=$STUPID_LOG_FILE
fi
if [ -z "$ZLOGFILE" ]; then
EVENT_LOG_FILE=""
export EVENT_LOG_FILE
fi
%s=`cd $reldir; pwd`
export %s
exec %s $%s/z2.py -D "$@" """
STOP_SCRIPT="#! /bin/sh\nkill `cat %s`"
...@@ -31,17 +31,24 @@ def stupid_log_write(subsystem, severity, summary, detail, error): ...@@ -31,17 +31,24 @@ def stupid_log_write(subsystem, severity, summary, detail, error):
# Check where to log # Check where to log
global _stupid_dest, _stupid_format global _stupid_dest, _stupid_format
if _stupid_dest is None: if _stupid_dest is None:
if os.environ.has_key('STUPID_LOG_FILE'): # EVENT_LOG_FILE is the preferred environment variable, but
f=os.environ['STUPID_LOG_FILE'] # we accept STUPID_LOG_FILE as well
eget = os.environ.get
f = eget('EVENT_LOG_FILE') or eget('STUPID_LOG_FILE')
if f is not None: # if the envvar exists (might still be null)
if f: _stupid_dest=open(f,'a') if f: _stupid_dest=open(f,'a')
else: _stupid_dest=sys.stderr else: _stupid_dest=sys.stderr
elif os.environ.get('Z_DEBUG_MODE',0): elif eget('Z_DEBUG_MODE'):
_stupid_dest=sys.stderr _stupid_dest=sys.stderr
else: else:
_stupid_dest=_no_stupid_log _stupid_dest=_no_stupid_log
if os.environ.has_key('STUPID_LOG_FORMAT'): # EVENT_LOG_FORMAT is the preferred environment variable, but
_stupid_format = os.environ['STUPID_LOG_FORMAT'] # we accept STUPID_LOG_FORMAT as well
fmt = eget('EVENT_LOG_FORMAT') or eget('STUPID_LOG_FORMAT')
if fmt is not None:
_stupid_format = fmt
# Check id to log # Check id to log
...@@ -49,7 +56,11 @@ def stupid_log_write(subsystem, severity, summary, detail, error): ...@@ -49,7 +56,11 @@ def stupid_log_write(subsystem, severity, summary, detail, error):
global _stupid_severity global _stupid_severity
if _stupid_severity is None: if _stupid_severity is None:
try: _stupid_severity=int(os.environ['STUPID_LOG_SEVERITY']) eget = os.environ.get
# EVENT_LOG_SEVERITY is the preferred environment variable, but
# we accept STUPID_LOG_SEVERITY as well
envvar = eget('EVENT_LOG_SEVERITY') or eget('STUPID_LOG_SEVERITY')
try: _stupid_severity=int(envvar)
except: _stupid_severity=0 except: _stupid_severity=0
if severity < _stupid_severity: return if severity < _stupid_severity: return
...@@ -67,8 +78,8 @@ def stupid_log_write(subsystem, severity, summary, detail, error): ...@@ -67,8 +78,8 @@ def stupid_log_write(subsystem, severity, summary, detail, error):
except: except:
failedf, _stupid_format = _stupid_format, None failedf, _stupid_format = _stupid_format, None
_stupid_dest.write("------\n%s %s zLOG Format string error\n" _stupid_dest.write("------\n%s %s zLOG Format string error\n"
"The STUPID_LOG_FORMAT string '%s' " "The EVENT_LOG_FORMAT or STUPID_LOG_FORMAT"
"caused an error, so we won't use it.\n" % "string '%s' caused an error, it wont be used."%
(fmap['time'], (fmap['time'],
severity_string(100), severity_string(100),
failedf) failedf)
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
# #
############################################################################## ##############################################################################
__version__='$Revision: 1.8 $'[11:-2] __version__='$Revision: 1.9 $'[11:-2]
import os, sys, time import os, sys, time
...@@ -54,8 +54,11 @@ class stupid_log_write: ...@@ -54,8 +54,11 @@ class stupid_log_write:
def initialize(self): def initialize(self):
global _log_dest, _log_level global _log_dest, _log_level
eget = os.environ.get
path = os.environ.get('STUPID_LOG_FILE', None) # EVENT_LOG_FILE is the preferred envvar, but we accept
# STUPID_LOG_FILE also
path = eget('EVENT_LOG_FILE') or eget('STUPID_LOG_FILE')
if path is None: if path is None:
_log_dest = None _log_dest = None
else: else:
...@@ -64,7 +67,9 @@ class stupid_log_write: ...@@ -64,7 +67,9 @@ class stupid_log_write:
else: else:
_log_dest = sys.stderr _log_dest = sys.stderr
severity = os.environ.get('STUPID_LOG_SEVERITY', None) # EVENT_LOG_SEVERITY is the preferred envvar, but we accept
# STUPID_LOG_SEVERITY also
severity = eget('EVENT_LOG_SEVERITY') or eget('STUPID_LOG_SEVERITY')
if severity: if severity:
_log_level = int(severity) _log_level = int(severity)
else: else:
......
...@@ -72,21 +72,21 @@ The callable object can provide a reinitialize method that may be ...@@ -72,21 +72,21 @@ The callable object can provide a reinitialize method that may be
called with no arguments to reopen the log files (if any) as part of a called with no arguments to reopen the log files (if any) as part of a
log-rotation facility. log-rotation facility.
There is a default stupid logging facility that: There is a default event logging facility that:
- swallows logging information by default, - swallows logging information by default,
- outputs to sys.stderr if the environment variable - outputs to sys.stderr if the environment variable
STUPID_LOG_FILE is set to an empty string, and EVENT_LOG_FILE is set to an empty string, and
- outputs to file if the environment variable - outputs to file if the environment variable
STUPID_LOG_FILE is set to a file name. EVENT_LOG_FILE is set to a file name.
- Ignores errors that have a severity < 0 by default. This - Ignores errors that have a severity < 0 by default. This
can be overridden with the environment variable STUPID_LOG_SEVERITY can be overridden with the environment variable EVENT_LOG_SEVERITY
""" """
__version__='$Revision: 1.5 $'[11:-2] __version__='$Revision: 1.6 $'[11:-2]
from MinimalLogger import log_write, log_time, severity_string, \ from MinimalLogger import log_write, log_time, severity_string, \
_set_log_dest _set_log_dest
......
...@@ -32,10 +32,9 @@ class StupidLogTest(unittest.TestCase): ...@@ -32,10 +32,9 @@ class StupidLogTest(unittest.TestCase):
"""Test zLOG with the default implementation. """Test zLOG with the default implementation.
The default implementation uses the environment variables The default implementation uses the environment variables
STUPID_LOG_FILE and STUPID_LOG_SEVERITY. I am not making this STUPID_LOG_FILE and STUPID_LOG_SEVERITY.
up.
""" """
prefix = 'STUPID'
def setUp(self): def setUp(self):
self.path = tempfile.mktemp() self.path = tempfile.mktemp()
self._severity = 0 self._severity = 0
...@@ -47,13 +46,17 @@ class StupidLogTest(unittest.TestCase): ...@@ -47,13 +46,17 @@ class StupidLogTest(unittest.TestCase):
pass pass
if os.environ.has_key('STUPID_LOG_FILE'): if os.environ.has_key('STUPID_LOG_FILE'):
del os.environ['STUPID_LOG_FILE'] del os.environ['STUPID_LOG_FILE']
if os.environ.has_key('EVENT_LOG_FILE'):
del os.environ['EVENT_LOG_FILE']
if os.environ.has_key('STUPID_LOG_SEVERITY'): if os.environ.has_key('STUPID_LOG_SEVERITY'):
del os.environ['STUPID_LOG_SEVERITY'] del os.environ['STUPID_LOG_SEVERITY']
if os.environ.has_key('EVENT_LOG_SEVERITY'):
del os.environ['EVENT_LOG_SEVERITY']
def setLog(self, severity=0): def setLog(self, severity=0):
os.environ['STUPID_LOG_FILE'] = self.path os.environ['%s_LOG_FILE' % self.prefix] = self.path
if severity: if severity:
os.environ['STUPID_LOG_SEVERITY'] = str(severity) os.environ['%s_LOG_SEVERITY' % self.prefix] = str(severity)
self._severity = severity self._severity = severity
zLOG.MinimalLogger._log.initialize() zLOG.MinimalLogger._log.initialize()
...@@ -128,8 +131,14 @@ class StupidLogTest(unittest.TestCase): ...@@ -128,8 +131,14 @@ class StupidLogTest(unittest.TestCase):
self.verifyEntry(f, subsys="basic", severity=zLOG.ERROR, self.verifyEntry(f, subsys="basic", severity=zLOG.ERROR,
error=err) error=err)
class EventLogTest(StupidLogTest):
""" Test alternate envvars EVENT_LOG_FILE and EVENT_LOG_SEVERITY """
prefix = 'EVENT'
def test_suite(): def test_suite():
return unittest.makeSuite(StupidLogTest, 'check') suite = unittest.makeSuite(StupidLogTest, 'check')
suite.addTest(unittest.makeSuite(EventLogTest, 'check'))
return suite
if __name__ == "__main__": if __name__ == "__main__":
loader = unittest.TestLoader() loader = unittest.TestLoader()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment