Commit 22e838ba 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 e9231a5f
......@@ -11,7 +11,7 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__version__='$Revision: 1.8 $'[11:-2]
__version__='$Revision: 1.9 $'[11:-2]
import os, sys, time
......@@ -54,8 +54,11 @@ class stupid_log_write:
def initialize(self):
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:
_log_dest = None
else:
......@@ -64,7 +67,9 @@ class stupid_log_write:
else:
_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:
_log_level = int(severity)
else:
......
......@@ -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
log-rotation facility.
There is a default stupid logging facility that:
There is a default event logging facility that:
- swallows logging information by default,
- 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
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
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, \
_set_log_dest
......
......@@ -32,10 +32,9 @@ class StupidLogTest(unittest.TestCase):
"""Test zLOG with the default implementation.
The default implementation uses the environment variables
STUPID_LOG_FILE and STUPID_LOG_SEVERITY. I am not making this
up.
STUPID_LOG_FILE and STUPID_LOG_SEVERITY.
"""
prefix = 'STUPID'
def setUp(self):
self.path = tempfile.mktemp()
self._severity = 0
......@@ -47,13 +46,17 @@ class StupidLogTest(unittest.TestCase):
pass
if os.environ.has_key('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'):
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):
os.environ['STUPID_LOG_FILE'] = self.path
os.environ['%s_LOG_FILE' % self.prefix] = self.path
if severity:
os.environ['STUPID_LOG_SEVERITY'] = str(severity)
os.environ['%s_LOG_SEVERITY' % self.prefix] = str(severity)
self._severity = severity
zLOG.MinimalLogger._log.initialize()
......@@ -128,8 +131,14 @@ class StupidLogTest(unittest.TestCase):
self.verifyEntry(f, subsys="basic", severity=zLOG.ERROR,
error=err)
class EventLogTest(StupidLogTest):
""" Test alternate envvars EVENT_LOG_FILE and EVENT_LOG_SEVERITY """
prefix = 'EVENT'
def test_suite():
return unittest.makeSuite(StupidLogTest, 'check')
suite = unittest.makeSuite(StupidLogTest, 'check')
suite.addTest(unittest.makeSuite(EventLogTest, 'check'))
return suite
if __name__ == "__main__":
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